这是我想处理的情况,引用自 Apple 的文档。
As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon. If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).
If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification . If the application icon is clicked on a computer running OS X, the application calls the delegate’s applicationDidFinishLaunching: method in which the delegate can obtain the remote-notification payload.
没有通知信息怎么办?
最佳答案
如果我对您的理解正确,听起来您有一个 UILocalNotification 已被触发,但如果用户点击应用程序图标而不是通知,您仍然需要处理它。正确吗?
如果是这种情况,那么据我所知,您将无法处理来自应用程序委托(delegate)的通知,因为应用程序不是通过通知启动或退出后台的,而是由用户的互动。
但是,如果您在带有通知的应用程序上设置 badgeNumber,那么您可以尝试这样的操作:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
} else if ([UIApplication sharedApplication].applicationIconBadgeNumber > 0) {
// Assume that user launched the app from the icon with a notification present.
}}
您可能还必须检查 - (void)applicationDidBecomeActive:(UIApplication *)application
中的 badgeNumber。
关于ios - 当用户按下图标而不是警报时处理本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24540304/