I am React Native engineer trying to understand/learn objective c.
I was going through Uber Startup screen reporter code, and have some difficulties understanding the code
Here is the code sample they have shared
Can someone explain me the flow of code?
What I have been doing (not sure if it is correct).
In AppDelegate.h, Added notification relay
@property (nonatomic, strong) UBApplicationStartupReasonReporterNotificationRelay *notificationRelay;
In AppDelegate.mm
I have added these delegate they shared..
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self.notificationRelay updateApplicationStateNotification:[NSNotification notificationWithName:UIApplicationDidBecomeActiveNotification object:nil]];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[self.notificationRelay updateApplicationStateNotification:[NSNotification notificationWithName:UIApplicationWillResignActiveNotification object:nil]];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[self.notificationRelay updateApplicationStateNotification:[NSNotification notificationWithName:UIApplicationWillTerminateNotification object:nil]];
}
then I created a new Cocoa Touch class and add this code there (inside shared instance), something like this.
- (instancetype)init
{
if (self = [super init]) {
// Determine whether the app crashed on a prior launch
BOOL crashedOnPriorLaunch = false;
// Initialize a storage mechanism implementing UBApplicationStartupReasonReporterPriorRunInfoProtocol
id<UBApplicationStartupReasonReporterPriorRunInfoProtocol> runInfo = ...
// Initialize the notification relay
id<UBApplicationStartupReasonReporterNotificationRelayProtocol> = [[UBApplicationStartupReasonReporterNotificationRelay alloc] init]
// Initialize the startup reason reporter
UBApplicationStartupReasonReporter *startupReasonReporter = [[UBApplicationStartupReasonReporter alloc] initWithPreviousRunDidCrash:crashedOnPriorLaunch
previousRunInfo:runInfo
notificationRelay: notificationRelay
debugging:[UBBuildType isDebugBuild]];
// Profit
UBStartupReason startupReason = startupReasonReporter.startupReason;
}
return self;
}
[Question:]
I am not sure how is the value of UBStartupReason startupReason = startupReasonReporter.startupReason; going to update? For example we have applicationDidBecomeActive and applicationWillResignActive which are two separate event.