ios - 在应用程序处于后台时获取本地通知

标签 ios localnotification

当应用程序在后台时,不会调用 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/

相关文章:

ios - 无法更改后退按钮标题,但我可以隐藏它

ios - 你如何在 Xcode 中声明一个全局变量?

ios - 以编程方式为我的 NavigationBar 创建了一个标题,但是没有出现在正确的位置?

ios - 如何将身份验证 token 从 Parse SDK 传递到 Fabric TwitterKit?

ios - 应用程序关闭时如何处理 UNNotificationAction?

ios - iOS 中的 OpenGL ES 2.0 和默认 FrameBuffer

dart - 在Flutter中关闭应用程序后如何接收本地通知?

android - cordova本地通知点击事件参数为空

ios - 计算待处理的本地通知

javascript - Ionic Framework 不工作时每小时发出一次本地通知?