通过点击通知获取推送通知并打开应用后,在nil
中收到didFinishLaunchWithOptions
的可能原因是什么?我已经仔细检查过应用程序已停止,而不仅仅是在后台。 nil
仍然始终写入日志。
我在didFinishLaunchWithOptions
中没有做任何特别的事情,这是代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[MA init];
NSLog(@"%@", launchOptions);
if (!launchOptions) {
return YES;
}
id userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo[@"aps"] && userInfo[@"id"]) {
MAResult* result = [[MA data] resultById:userInfo[@"id"]];
if (result) {
[((UINavigationController *)self.window.rootViewController) pushViewController:[[MATaskDetails alloc] initWithResults:result] animated:YES];
}
}
return YES;
}
答案 0 :(得分:0)
您可以尝试使用didReceiveRemoteNotification委托方法
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[MA init];
NSLog(@"%@", Received Notification);
if (userInfo[@"aps"] && userInfo[@"id"]) {
MAResult* result = [[MA data] resultById:userInfo[@"id"]];
if (result) {
[((UINavigationController *)self.window.rootViewController) pushViewController:[[MATaskDetails alloc] initWithResults:result] animated:YES];
}
}
}
希望它可以帮助你....!
答案 1 :(得分:-1)
如果应用处于前台模式,则会通过application:didReceiveRemoteNotification:
但如果应用程序未处于前台模式,则推送通知将传递到application:didFinishLaunchingWithOptions:
所以我相信你以前台模式申请并application:didFinishLaunchingWithOptions:
根本没有被召唤。