且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用程序didReceiveLocalNotification未触发iOS7

更新时间:2023-02-03 09:56:23

您的应用程序是在后台还是前台?如果它在前台,我很确定该方法被调用。如果不是,也许您没有将该方法放在您的应用程序委托中。

Is your application in the background or foreground? If it's in the foreground, I'm pretty sure that method is called. If it isn't, maybe you aren't putting that method in your application delegate.

如果它在后台,这里有几种可能的情况:

If it's on the background, here's a few possible scenarios:


  1. 您的应用已被用户或操作系统杀死。在这种情况下,当用户通过点击通知中心上的通知(或在锁定屏幕中滑动)唤醒您的应用程序时,您的应用程序代理将具有应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法调用。您可以通过以下方式获取此方法的通知:

  1. Your app has been killed by the user or the OS. In this case when the user wake up your app by tapping on the notification on the notification centre (or swiping in lock screen), your application delegate will have the application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method called. You can get the notification from this method by:

[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

您的应用程序位于后台,用户点击通知中心或锁定屏幕中的通知。在这种情况下,没有委托方法将被称为。该文档明确指出 didReceiveLocalNotification:适用于应用程序位于前台的时间:

Your app is in background, and the user tap on the notification in notification centre or lock screen. In this case, no delegate methods will be called. The documentation specifically said that didReceiveLocalNotification: is for when the app is in the foreground:




如果应用程序在前台运行,则没有警报,徽章,
或声音;相反,应用程序:didReceiveLocalNotification:方法
如果委托实现它则被调用。

If the app is running in the foreground, there is no alert, badging, or sound; instead, the application:didReceiveLocalNotification: method is called if the delegate implements it.

所以希望你可以通知在收到通知时决定该怎么做。我个人觉得当用户通过点击图标(而不是通知)启动应用程序时,我们没有获得通知对象有点奇怪。但我现在只是写下我的逻辑。

So hopefully you can make an informed decision about what to do when you receive the notification. I personally find it a little bit weird that we don't get the notification object when the user launches the app by tapping the icon (not the notification). But I currently just write my logic around it.