當一個通知彈出時,您可以查看它或取消。如果用戶已經取消通知,您可以檢查他們的下一個他們在應用程序中去時間:
- (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: