override func application(application: UIApplication,didReceiveRemoteNotification userInfo: [NSObject : AnyObject],fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { println("hey) }
当我发送推送通知时,我成功地使用该应用在前台调用的方法.
如果我覆盖
override func application(application: UIApplication,didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { println("hey") }
在前台发送通知应用程序时,我没有收到任何方法的调用.为什么第一个工作,但第二个没有应用程序在前台?
请注意,我只是一次执行其中之一.不是同时两个.
解决方法
Implement the
application:didReceiveRemoteNotification:fetchCompletionHandler:
method instead of this one whenever possible. If your delegate implements both methods,the app object calls theapplication:didReceiveRemoteNotification:fetchCompletionHandler:
method.
旧版本还将根据应用程序是否有效(前景或背景)或从冷启动启动而提供不同的结果.在后一种情况下,它不会被调用,您将需要截取didOfficeLaunchingWithOptions的launchOptions dict来获取infoDict:
If the app is not running when a remote notification arrives,the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification.
使用回调版本.适用于所有情况.您不必使用完成处理程序/块,在这种情况下,效果是相同的(更符合较新的方法).
更新
对不起,苹果说你必须尽快打电话给完成块“ – 在操作系统放弃你之前你有30秒钟的时间.这可能是您的警告的根源.
As soon as you finish processing the notification,you must call the block in the handler parameter or your app will be terminated. Your app has up to 30 seconds of wall-clock time to process the notification and call the specified completion handler block. In practice,you should call the handler block as soon as you are done processing the notification.
所以调用完成块:
completionHandler(UIBackgroundFetchResult.NoData)
我一直在使用这种方法,而不用调用那个完成块,没有遇到任何问题,但是我现在只需要加一个来安全.苹果建议,如果你不这样做,你的应用程序将不会出现,但实际上我没有看到.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。