关于remote-notification
- 问题:在启动程序时,日志里面打印了:You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
这句话的意思是我们在UIApplicationDelegate中实现了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,但没有在Info.plist中的UIBackgroundModes添加remote-notification。之前做这个推送的同事说这个提示没有关系,一直都有这句提示的,而且我们的推送功能一直是正常的。但是我心里还是有些疑问,那就问问度娘吧。
解决方案:
原文:http://www.cnblogs.com/yonggezai/p/4826713.html
这句话主要是提示开发者如果要支持UIBackgroundModes,需要开启Remote notifications,具体操作可以看:iOS 7 Background Remote Notification。
看了半天,还是没有理解Remote notifications有什么特点,后来在知乎上看到了一个问题“为什么iOS伪后台,但是有很多软件也会在后台一直运行?”,有一个答案对remote notificaions解释的很清楚:
推送唤醒(remote notifications)iOS7以前,当你收到推送消息时,你需要先打开应用,等待应用从网络上获取推送的信息之后,才能将信息呈现出来。而iOS7改变了这一过程。当系统收到推送消息时,不是首先提醒用户,而是唤醒对应的应用,让应用在后台获取对应的信息。当信息处理完成后,再提醒用户。一个很小的改变,但是可以很大的提升用户体验。同样,iOS系统也会限制这种推送消息的频率,防止系统被频繁唤醒影响续航。
——来自知乎网友Jeffrey Lin
这个时候再结合那两张 Apple 官方对IOS6和iOS7对比的图片,就很容易理解了。


UIApplicationDelegate中提供了两个方法来处理推送的回调,其中第二个方法是iOS7以后才有的:
// 如果app在前台运行,系统收到推送时会调用该方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
}
// 不管app是在前台运行还是在后台运行,系统收到推送时都会调用该方法
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
/* Use this method to process incoming remote notifications for your app.
* Unlike the application:didReceiveRemoteNotification: method,
* which is called only when your app is running in the foreground,
* the system calls this method when your app is running in the foreground or background.
}
这两个方法长得很像,但是职责不同,。
现在的问题是:
1.我们实现了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,但没有设置UIBackgroundModes的remote-notification,有什么影响吗?
2.既然有了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,为什么还要application:didReceiveRemoteNotification: 呢?
我测试了一下两个遗留问题:
1.我们实现了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,但没有设置UIBackgroundModes的remote-notification,有什么影响吗?
不设置UIBackgroundModes的remote-notification的话,除了推送唤醒功能不生效之外,没发现有其他影响。
2.既然有了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,为什么还要application:didReceiveRemoteNotification: 呢?
我看了API文档,是这么说的:
Implement the "application:didReceiveRemoteNotification:fetchCompletionHandler:" method instead of this one(application:didReceiveRemoteNotification:) whenever possible.
If your delegate implements both methods, the app object calls the "application:didReceiveRemoteNotification:fetchCompletionHandler:" method.
所以application:didReceiveRemoteNotification:方法应该是没用了。
转自 祥龙Shannon
原文:http://www.jianshu.com/p/9a25418ab84e
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性