应用程序didReceiveLocalNotification未触发iOS7 [英] application didReceiveLocalNotification not fired iOS7

查看:135
本文介绍了应用程序didReceiveLocalNotification未触发iOS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

- (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

有时使用iOS7不会调用


它不会影响我们如何安排通知:

is not called sometimes with iOS7. It doesn't mater how we schedule the notification:

alarm.fireDate = [[NSDate date] dateByAddingTimeInterval:0.1];
[app scheduleLocalNotification:alarm];

或:

[app presentLocalNotificationNow:alarm];

我的想法:
当用户在通知提醒动画之前滑动时会发生这种情况完了。
如果他在滑动之前等了半秒钟 - 通知被解雇,应用程序按预期进行。
问题可能是应用程序在收到通知之前进入前台。

My thoughts: This happens in the case when the user slides before the notification alert animation is finished. And if he waits just a half second before he slides - the notification is fired and the App proceeds as expected. The problem probably is that application enters foreground before the notification is received.

有没有人满足这个要求?这是一个错误吗?有解决方案吗谢谢!

Did anyone meet this? Is it a bug? Any solution? Thank you!

推荐答案

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

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.

这篇关于应用程序didReceiveLocalNotification未触发iOS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆