In my app, I push local notifications after the user does a certain action.
When the user opens the app from the pushed notification, I want to register an event to a tracking system (in my case is Mixpanel).
I should have a key to register the event which I'm getting this from my server.
So what I want to do is to get the key in a function and after this function has finished, I want to register the event.
I tried performSelectorOnMainThread:withObject:waitUntilDone:
but it didn't work
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//some code here
[self performSelectorOnMainThread:@selector(performHandShake)
withObject:nil
waitUntilDone:YES];
[self performSelectorOnMainThread:@selector(registerLaunchOptionsDetails:)
withObject:launchOptions
waitUntilDone:YES];
//some code here
}
-(void)performHandShake
{
//myParams here
[[RKClient sharedClient] get:@"/handshake" usingBlock:^(RKRequest *request) {
request.params = [RKParams paramsWithDictionary:myParams];
request.method = RKRequestMethodGET;
request.onDidLoadResponse = ^(RKResponse *response) {
//Set the tracking key here
};
request.onDidFailLoadWithError = ^(NSError *error) {
NSLog(@"ERROR:%@",error);
};
}];
}
-(void)registerLaunchOptionsDetails:(NSDictionary *)launchOptions
{
UILocalNotification *localNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
//Register the event here using the key
}
}
The problem is the registerLaunchOptionsDetails
function performed before performHandShake
is completed and the events are not being registered.