简体   繁体   English

如何知道应用程序在后台时是否触发了本地通知?

[英]How can I tell if a local notification was fired while the application was in the background?

I need to run specific code if a local notification was fired while the application was in the background and has now entered the foreground. 如果在应用程序处于后台并且现在进入前台时触发了本地通知,则我需要运行特定的代码。 One way to do this is to get the badge count, is there a better way? 一种方法是获取徽章计数,还有更好的方法吗?

Check out the docs at http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html上查看文档

Your App Delegate can detect notifications when the app is in the background 当应用程序在后台运行时,您的应用程序代表可以检测到通知

   - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {

    NSString *itemName = [notif.userInfo objectForKey:ToDoItemKey]

    [viewController displayItem:itemName];  // custom method

    application.applicationIconBadgeNumber = notification.applicationIconBadgeNumber-1;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道在应用程序处于后台时是否触发了本地通知? - How to know if a local notification was fired while the app is in background? 如何在 flutter 后台收到本地通知时调用 function - How can I call a function on local notification received in background in flutter iOS - 如何判断本地通知是否导致我的应用程序进入前台? - iOS - How can I tell if a Local Notification caused my app to enter foreground? 如何知道越狱电话中触发了哪些iOS通知 - How to tell what fired IOS notification in Jailbroken phone 应用程序进入后台时如何发送本地通知 - How to send local notification when application goes to background 如何在IOS中触发通知后删除本地通知 - How to remove local notification after fired notification in IOS 我可以从后台取消iOS本地通知吗? - Can I cancel iOS local notification from the background? 我如何知道该应用在后台被杀死后是否已从本地通知中打开? - How can I know if the app has been opened from a local notification after it has been killed in the background? 在 Xcode 中,我如何显示“前景和背景”模式的本地通知? - in Xcode how can i show local notification of both "foreground and background" mode? 当应用程序处于后台时,如何显示自定义本地通知视图或自定义警报视图? - How can I show a custom Local notification View or an Custom Alert view when app is in Background?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM