• 关于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

  • 相关阅读:
    vue+drf+第三方滑动验证码的接入实现
    基于k8s Ingress Nginx+OAuth2+Gitlab无代码侵入实现自定义服务的外部验证
    [转] Java 命名规范
    npm 下载慢问题解決方案
    java float跟double类型区别
    select、input为什么不能使用after before
    es6数组方法详解
    pytest-pytest.main()运行测试用例,pytest参数
    Selenium截屏 图片未加载的问题解决--【懒加载】
    selenium元素定位中的iframe切换问题总结
  • 原文地址:https://www.cnblogs.com/LoveStoryJX/p/6491615.html
Copyright © 2020-2023  润新知