• iOS接收远程通知响应方法


    点击 iOS 接收远程推送主要牵扯到的方法有以下五种

    (1) - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    (2) - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    (3) - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
    (4) - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
    (5) - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
    
    1. 会在app启动完成调用 launchOptions 保存了app启动的原因信息,如果app是因为点击通知栏启动的,可以在 launchOptions 获取到通知的具体内容。
    2. 会在接收到通知的时候调用,在最新的iOS 10中已经废弃,建议不再使用。
    3. 是在iOS 7之后新增的方法,可以说是 2 的升级版本,如果app最低支持iOS 7的话可以不用添加 2了。
      其中completionHandler这个block可以填写的参数UIBackgroundFetchResult是一个枚举值。主要是用来在后台状态下进行一些操作的,比如请求数据,操作完成之后,必须通知系统获取完成,可供选择的结果有
    typedef NS_ENUM(NSUInteger, UIBackgroundFetchResult) {
        UIBackgroundFetchResultNewData,
        UIBackgroundFetchResultNoData,
        UIBackgroundFetchResultFailed
    }
    

    分别表示获取到了新数据(此时系统将对现在的UI状态截图并更新App Switcher中你的应用的截屏),没有新数据,以及获取失败。不过以上操作的前提是已经在Background Modes里面勾选了Remote notifications(推送唤醒)且推送的消息中包含content-available字段。

    1. 是 iOS 10 新增的UNUserNotificationCenterDelegate代理方法,在 iOS 10的环境下,点击通知栏都会调用这个方法。
    2. 也是 iOS 10 新增的UNUserNotificationCenterDelegate代理方法,在iOS 10 以前,如果应用处于前台状态,接收到推送,通知栏是不会又任何提示的,如果开发者需要展示通知,需要自己在 3 的方法中提取通知内容展示。在iOS 10中如果开发者需要前台展示通知,可以再在这个方法中completionHandler传入相应的参数。
    typedef NS_OPTIONS(NSUInteger, UNNotificationPresentationOptions) {
        UNNotificationPresentationOptionBadge   = (1 << 0),
        UNNotificationPresentationOptionSound   = (1 << 1),
        UNNotificationPresentationOptionAlert   = (1 << 2),
    } 
    

    总结:(最低系统环境为iOS 7)

    • 当程序处于关闭状态的时候收到推送消息,点击应用程序图标无法获取推送消息, iOS 10 环境下,点击通知栏会调用 方法1与4。非iOS 10的情况下,会调用方法1与3。
    • 当程序处于前台状态下收到推送消息,iOS 10的环境下如果推送的消息中包含content-available字段的话执行方法3与4,否则只执行4。非iOS 10的情况下会执行方法3。
    • 当程序处于后台收到推送消息,如果已经在Background Modes里面勾选了Remote notifications(推送唤醒)且推送的消息中包含content-available字段的话,都会执行方法3。点击通知栏 iOS 10会执行方法4,非iOS10会执行方法3。




    转自:https://www.jianshu.com/p/5bd30a890c90

  • 相关阅读:
    数型DP
    士兵杀敌(三)(RMQ)(DP) or ( 线段树 )
    还是回文
    dp(DAG)
    mysql的内连接外连接查询
    一些概念
    函数式编程中的一些概念
    Optional<T>
    计算文件和字符串的MD5摘要
    SpringMVC的一些配置
  • 原文地址:https://www.cnblogs.com/yang-shuai/p/9106159.html
Copyright © 2020-2023  润新知