【发布时间】:2014-01-29 15:56:42
【问题描述】:
在我的应用中,我会在用户执行特定操作后推送本地通知。
当用户从推送的通知中打开应用程序时,我想将事件注册到跟踪系统(在我的例子中是 Mixpanel)。
我应该有一个密钥来注册从我的服务器获取的事件。
所以我想做的是在一个函数中获取密钥,在这个函数完成后,我想注册事件。
我试过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
}
}
问题是在performHandShake 完成之前执行的registerLaunchOptionsDetails 函数并且没有注册事件。
【问题讨论】:
-
可以在握手函数的最后调用
registerLaunchOptionsDetails函数吗? -
在这种情况下,您只需要使用 Grand Central Dispatch。在这些情况下建议使用队列
-
尝试从 onDidLoadResponse 块调用 callregisterLaunchOptionsDetails?
-
@Ali 我试过了,但它对我不起作用,我认为原因是我没有完全理解它。有什么好的例子推荐的链接吗?
-
@alex 谢谢你,它有效。您可以添加您的评论作为答案,我会接受。
标签: ios objective-c performselector localnotification