在我的应用中,我会在用户执行特定操作后推送本地通知。
当用户从推送的通知打开应用程序时,我想向跟踪系统注册一个事件(在我的例子中是 Mixpanel)。
我应该有一个 key 来注册我从服务器获取的事件。
所以我想做的是在一个函数中获取键,在这个函数完成后,我想注册事件。
我尝试了 performSelectorOnMainThread:withObject:waitUntilDone:
但没有成功
- (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
}
}
问题是 registerLaunchOptionsDetails
函数在 performHandShake
完成之前执行,并且没有注册事件。
最佳答案
对于你想做的事情来说可能有点矫枉过正,但是有一个类似于 async for node 的库。您可以将异步任务链接在一起和/或等到多个任务完成后再执行另一个操作。
关于ios - 只有在第一个功能完成后才执行一个功能 - ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21436097/