你是对的。该行为与文档不一致。将文档放在一边,专注于实际行为;问题的症结似乎是这样的:如果您的应用程序通过用户与通知交互而变为活动状态,您将收到指向通知的指针,如果用户直接点击您的应用程序图标,您将不会收到。
为了显示。如果您呈现警报样式通知并且用户点击操作按钮,或者在您的情况下,如果您呈现横幅通知并且用户点击您将通过以下两种方式之一收到指向通知的指针:
如果您的应用程序处于未运行状态:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UILocalNotification *launchNote = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (launchNote){
// I recieved a notification while not running
}
}
如果您的应用程序在任何状态下运行:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
// I recieved a notification
}
在用户选择取消警报样式通知的情况下,该通知将消失。
The truly annoying an inconsistent part is that if you present a banner notification and the user taps your icon you seem to have no way of retrieving a reference to the presented notifications in the notification center. i.e. they do not appear in the [[UIApplication sharedApplication] scheduledLocalNotifications]
array, presumably because they are no longer scheduled but are now presented.
So in short; The documentation is wrong. And there are other annoying inconsistencies. If this behavior is a problem for you you should file a bug with Apple.