gpt4 book ai didi

ios - 为什么收到推送通知后launchOptions为nil?

转载 作者:行者123 更新时间:2023-12-02 03:03:32 24 4
gpt4 key购买 nike

收到推送通知并通过点击通知打开应用程序后,在 didFinishLaunchWithOptions 中收到 nil 的可能原因是什么?我已经仔细检查应用程序是否已停止,而不仅仅是在后台。并且 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;
}

最佳答案

您可以尝试使用 didReceiveRemoteNotification 委托(delegate)方法

- (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];
}
}
}

希望对你有帮助......!

关于ios - 为什么收到推送通知后launchOptions为nil?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22659590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com