当应用程序在后台时,不会调用 didReceiveLocalNotification。
所以我尝试从 didFinishLaunchingWithOptions 获取通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
//...
}
但我的应用启用了后台模式(使用外部附件通信) 单击通知时,不会调用 didFinishLaunchingWithOptions。
还有其他方法可以获取通知吗?
最佳答案
通过检查Apple's document关于通知,它说:
iOS Note: In iOS, you can determine whether an application is launched as a result of the user tapping the action button or whether the notification was delivered to the already-running application by examining the application state. In the delegate’s implementation of the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method, get the value of the applicationState property and evaluate it. If the value is UIApplicationStateInactive, the user tapped the action button; if the value is UIApplicationStateActive, the application was frontmost when it received the notification.
据我所知,当你的应用程序处于后台运行状态,并且有本地通知时,你不会收到任何方法调用,通知将显示给用户,但如果用户点击通知并因此响应您的应用程序,您将收到 -didReceiveLocalNotification:
电话。
关于ios - 在应用程序处于后台时获取本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25356064/