当一个通知弹出时,您可以查看它或取消。如果用户已经取消通知,您可以检查他们的下一个他们在应用程序中去时间:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if(localNotif) {
// Do some stuff
application.applicationIconBadgeNumber = 0; // Reset num of notifications on app icon
}
}
,如果你收到通知,而你在特定的应用程序,或者您选择确认,此方法被解雇本地通知:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
BOOL inApp = [application applicationState] == UIApplicationStateActive;
if(inApp) { // they got this in the app
//Do some stuff in the app
}
else {
// They acknowledged the notification out of the app and here they are
// Do some other stuff
}
application.applicationIconBadgeNumber = 0;
}
这就给了你很好的覆盖与本地通知所有场景具体做法是:
- 收到通知,用户取消。稍后检查didFinishLaunchingWithOptions
- 通知已确认,应用程序未打开。检入didFinishLaunchingWithOptions
- 通知被确认,该应用程序在后台。 didReceiveLocalNotification:
- 通知被呈现,而在该应用didReceiveLocalNotification: