关于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对比的图片,就很容易理解了。


Remote Notifications in iOS6.jpg

Remote Notifications in iOS7 .png

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

 

转载于:https://www.cnblogs.com/LoveStoryJX/p/6491615.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值