zoukankan      html  css  js  c++  java
  • iOS通知总结

    • App业务逻辑处理,活动,结果通知
    • 吸引用户眼球,提高用户留存度
    • 特殊场景的数据交互处理,如后台通知

    通知分类

    • 远程通知

      • Alert通知

        • 活动介绍
        • 支持声音(资源,)
        • 支持多媒体,依赖扩展提供,文本,可翻译
        • 支持锁屏便捷的Action处理,需要注册分类
        • 支持角标,app启动图片设置
      • 静默通知(支持后台唤起)

        • 后台数据更新,预加载
    • 本地通知

      • 用户计划事件,如会议,行程 ...
      • 三种条件触发,时间,日历,区域

    通知实现步骤

    1. 在AppDeveloper Center中打开appId的通知开关,配置证书(CSR/CER)
    2. Xcode功能配置通知开关,设置通知的运行模式,如果开启的远程通知,则需设置允许后台模式
    3. 配置通知授权的PlistKey
    4. 启动时请求通知授权,注册通知获取deviceToken
    5. 注册通知分类(optional)
    6. AppDelegate中通知注册成功的回调方法中获取deviceToken上传至服务器
    7. 配置通知中心代理,依照通知类型设定不同的handlers,处理静默与非静默通知,通知事件分发
    8. 处理静默和非静默两种不通的通知,内容Mapping
    9. 本地通知定制封装,配置category定制
    10. 通知中心的增删操作
    11. 拦截远程通知,在通知展示在App屏幕和传递app前进行处理, ContentExtension进行UI定制,ServiceExtension可以对通知数据进行处理(optional)
    12. 通知服务器接入,自己搭建,参考sending_notification_requests_to_apns, 集成它方的SDK
    13. 通知调试,PushMe baby,SamrtPush,Pusher
    14. 进阶版通知,ios8苹果新引入了名为pushkit的框架和一种新的push通知类型,被称作voip push

    注意事项

    1. 普通通知payload限定 1024*4kb
    2. voip通知payload限定 1024*5kb
    3. 后台不要推送太频繁,尽量限定在每小时3次以内
    4. deviceToken格式处理及上传

    通知相关流程

    • deviceToken注册简介
    • deviceToken注册详解

    • 不带扩展的通知推送

    • 带扩展的通知

    通知常用Payload速查

    • 带Category的前台通知
    {
       “aps” : {
          “alert” : {
             “title” : “Game Request”,
             “subtitle” : “Five Card Draw”
             “body” : “Bob wants to play poker”,
          },
          “category” : “GAME_INVITATION”
       },
       “gameID” : “12345678”
    }
    
    • 带声音的前台通知
    {
       “aps” : {
          “badge” : 9
          “sound” : “bingbong.aiff”
       },
       “messageID” : “ABCDEFGHIJ”
    }
    
    • 带翻译的前台通知
    {
       "aps" : {
          "alert" : {
             "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
             "loc-args" : [ "Shelly", "Rick"]
          }
       }
    }
    
    • 通知加密的payload的前台通知, ServiceExtension处理
    {
       “aps” : {
          “category” : “SECRET”,
          “mutable-content” : 1,
          “alert” : {
             “title” : “Secret Message!”,
             “body”  : “(Encrypted)”
         },
       },
       “ENCRYPTED_DATA” : “Salted__·öîQÊ$UDì_¶Ù∞è   Ω^¬%gq∞NÿÒQùw”
    }
    
    • 后台通知
    {
       "aps" : {
          "content-available" : 1
       },
       "acme1" : "bar",
       "acme2" : 42
    }
    
    • 注意事项
      • content-available,静默通知特有的标志
      • mutable-content: 表明通知内容可变,可以通过扩展拦截
      • aps平级部分为用户自定义字段
      • sound的路径查找
        • main bundle
        • Library
        • Group的Library
      • sound需小于30s
      • 翻译配置
        • 支持参数配置

    通知Key-Value介绍

    通知相关知识速查

    usernotifications

    sending_notification_requests_to_apns

    node js send set up a remote notification
    setting_up_a_remote_notification_server

    The Push Notifications primer

    Modifying Content in Newly Delivered Notifications

    pushing_background_updates_to_your_app

    generating_a_remote_notification

    pushing_background_updates_to_your_app

    RemoteNotificationsPG

    707_introduction_to_notifications.pdf
    File Provider iOS11.0

    using_push_notifications_to_signal_changes

    adding_notifications_to_your_watchos_app

    •    通知角标设置 ,
      当Alert设置为空的时候,只更新角标数字,不会有消息显示。
    "ios": {
                "alert": "",
                "sound": "default",
                "badge": "+3",
                "thread-id": "default",
                "content-available": false,
                "extras": {
                    "newsid": 321
                }
            },

                当 badge设设置为0的时候,会自动清除通知中心的角标,可以通过以下方式来清除角标但不清除通知

    - (void)setBadge:(FlutterMethodCall*)call result:(FlutterResult)result {
        JPLog(@"setBadge:%@",call.arguments);
        NSInteger badge = [call.arguments[@"badge"] integerValue];
        if (badge <= 0) {
            badge = -1;
        }
        [JPUSHService setBadge: badge];
        if (@available(iOS 10.0, *)) {
            /*
             iOS 11后,设置badgeNumber = -1    after iOS 10.0, set the badge number to -1, will not clear screen notification
             */
            [UIApplication sharedApplication].applicationIconBadgeNumber = badge;
        }else{
            UILocalNotification *clearEpisodeNotification = [[UILocalNotification alloc] init];
            clearEpisodeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:(0.3)];
            clearEpisodeNotification.timeZone = [NSTimeZone defaultTimeZone];
            clearEpisodeNotification.applicationIconBadgeNumber = badge;
            [[UIApplication sharedApplication] scheduleLocalNotification:clearEpisodeNotification];
        }
    }
  • 相关阅读:
    servlet的监听器、过滤器、拦截器的区别
    根据一个单词找所有的兄弟单词的思想如何处理
    Maven deploy 部署 jar 到 Nexus 私服
    在vps上搭建hexo博客
    Java解决LeetCode72题 Edit Distance
    学以致用:Python爬取廖大Python教程制作pdf
    puppeteer截图
    Netty接收HTTP文件上传及文件下载
    Docker中执行Shell出现乱码
    Netty URL路由方案探讨
  • 原文地址:https://www.cnblogs.com/wwoo/p/tong-zhi-zuo-yong.html
Copyright © 2011-2022 走看看