launchOptions 'UIApplicationLaunchOptionsLocalNotificationKey' 是否包含 NSDictionary 或 UILocalNotification
Does launchOptions 'UIApplicationLaunchOptionsLocalNotificationKey' contain NSDictionary or UILocalNotification
好的,所以我已经阅读了各种关于如何在 didfinishlaunchingwith 选项中检查本地通知的文章。例如,这篇 NSHipster 文章声称远程键和本地键都包含一个 NSDictionary。 http://nshipster.com/launch-options/
但是,我测试过,它包含一个 UILocalNotification,其他一些文章也是这样说的。
所以,我环顾四周,但没有找到任何明确的答案。这是 OS 版本问题吗?不同的版本包含不同的对象,还是什么?
不胜感激。
编辑:
来自 NSHipster 文章:
"本地通知填充 UIApplicationLaunchOptionsLocalNotificationKey 上的启动选项,其中包含与远程通知具有相同结构的负载:
UIApplicationLaunchOptionsLocalNotificationKey:表示本地通知可供应用程序处理。此键的值是包含本地通知有效负载的 NSDictionary。"
根据 Apple Documentation,UIApplicationLaunchOptionsLocalNotificationKey 会给你一个 UILocalNotification 对象。
If the default action button is tapped (on a device running iOS), the
system launches the app and the app calls its delegate’s
application:didFinishLaunchingWithOptions: method, passing in the
notification payload (for remote notifications) or the
local-notification object (for local notifications). Although
application:didFinishLaunchingWithOptions: isn’t the best place to
handle the notification, getting the payload at this point gives you
the opportunity to start the update process before your handler method
is called.
Apple 文档中的示例代码
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSString *itemName = [localNotif.userInfo objectForKey:ToDoItemKey];
[viewController displayItem:itemName]; // custom method
app.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber-1;
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
编辑: UIApplicationLaunchOptionsRemoteNotificationKey
的更新
UIApplicationLaunchOptionsRemoteNotificationKey
、returns NSDictionary 与 notification payload
同样来自苹果文档
The value of this key is the UILocalNotification object that was triggered. For additional information about handling local notifications, see the application:didReceiveLocalNotification: method.
apple-doc-UIApplicationLaunchOptionsLocalNotificationKey
注意:此键自 iOS10.0
后已弃用
didFinishLaunchingWithOptions:
中的 Options 参数是一个字典,根据 UIApplicationDelegate,UILocalNotification
可以作为键 UIApplicationLaunchOptionsLocalNotificationKey
的值包含在其中。
这与远程通知不同,远程通知是包含负载的 NSDictionary
,可以使用 UIApplicationLaunchOptionsRemoteNotificationKey
键获取。
UIApplicationLaunchOptionsRemoteNotificationKey
The presence of this key indicates that a remote notification is available for the app to process. The value of this key is an NSDictionary containing the payload of the remote notification. See the description of application:didReceiveRemoteNotification: for further information about handling remote notifications.
UIApplicationLaunchOptionsLocalNotificationKey
The presence of this key indicates that a local notification is available for the app to process. The value of this key is the UILocalNotification object that was triggered. For additional information about handling local notifications, see the application:didReceiveLocalNotification: method.
好的,所以我已经阅读了各种关于如何在 didfinishlaunchingwith 选项中检查本地通知的文章。例如,这篇 NSHipster 文章声称远程键和本地键都包含一个 NSDictionary。 http://nshipster.com/launch-options/
但是,我测试过,它包含一个 UILocalNotification,其他一些文章也是这样说的。
所以,我环顾四周,但没有找到任何明确的答案。这是 OS 版本问题吗?不同的版本包含不同的对象,还是什么?
不胜感激。
编辑:
来自 NSHipster 文章:
"本地通知填充 UIApplicationLaunchOptionsLocalNotificationKey 上的启动选项,其中包含与远程通知具有相同结构的负载:
UIApplicationLaunchOptionsLocalNotificationKey:表示本地通知可供应用程序处理。此键的值是包含本地通知有效负载的 NSDictionary。"
根据 Apple Documentation,UIApplicationLaunchOptionsLocalNotificationKey 会给你一个 UILocalNotification 对象。
If the default action button is tapped (on a device running iOS), the system launches the app and the app calls its delegate’s application:didFinishLaunchingWithOptions: method, passing in the notification payload (for remote notifications) or the local-notification object (for local notifications). Although application:didFinishLaunchingWithOptions: isn’t the best place to handle the notification, getting the payload at this point gives you the opportunity to start the update process before your handler method is called.
Apple 文档中的示例代码
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSString *itemName = [localNotif.userInfo objectForKey:ToDoItemKey];
[viewController displayItem:itemName]; // custom method
app.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber-1;
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
编辑: UIApplicationLaunchOptionsRemoteNotificationKey
UIApplicationLaunchOptionsRemoteNotificationKey
、returns NSDictionary 与 notification payload
同样来自苹果文档
The value of this key is the UILocalNotification object that was triggered. For additional information about handling local notifications, see the application:didReceiveLocalNotification: method.
apple-doc-UIApplicationLaunchOptionsLocalNotificationKey
注意:此键自 iOS10.0
后已弃用didFinishLaunchingWithOptions:
中的 Options 参数是一个字典,根据 UIApplicationDelegate,UILocalNotification
可以作为键 UIApplicationLaunchOptionsLocalNotificationKey
的值包含在其中。
这与远程通知不同,远程通知是包含负载的 NSDictionary
,可以使用 UIApplicationLaunchOptionsRemoteNotificationKey
键获取。
UIApplicationLaunchOptionsRemoteNotificationKey
The presence of this key indicates that a remote notification is available for the app to process. The value of this key is an NSDictionary containing the payload of the remote notification. See the description of application:didReceiveRemoteNotification: for further information about handling remote notifications.
UIApplicationLaunchOptionsLocalNotificationKey
The presence of this key indicates that a local notification is available for the app to process. The value of this key is the UILocalNotification object that was triggered. For additional information about handling local notifications, see the application:didReceiveLocalNotification: method.