美文网首页
react-native 消息推送

react-native 消息推送

作者: 朱传武 | 来源:发表于2021-02-15 17:33 被阅读0次

ios新建推送以及开发证书部分(略去)

创建私钥

openssl pkcs12 -in cred.p12 -nokeys -out cert.pem -nodes
openssl pkcs12 -in cred.p12 -nocerts -out key.pem -nodes
openssl rsa -in key.pem -out key.pem

Strip anything outside of "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" boundaries and outside of "-----BEGIN RSA PRIVATE KEY-----" and "-----END RSA PRIVATE KEY-----" boundaries before pasting them. Check the 'Sandbox' button if you made a development certificate. Sandbox is synonymous with development mode.


image.png

集成react-native-push-notification https://github.com/zo0r/react-native-push-notification

注意:ios需要额外集成https://github.com/react-native-push-notification-ios/push-notification-ios

控制台新建function

twillo推送可以使用云推送或者自己服务器端集成它的sdk来实现,我用的前者


image.png
image.png

新建之后,系统就非常人性化的创建了两个云函数,一个是绑定token和userid的接口,一个是推送给某个用户的接口。用post调试一下:


image.png
绑定接口:
image.png
发送消息接口:
image.png

云函数可以自己修改,比如原先没有title这个变量,可以自己添加:


image.png
最终效果:
image.png

其他

Notifications resource has channel specific parameters (payload) where you can specify information on how the user should be notified of a Push Notification, including displaying a badge on the app icon. To do that, just add "badge" : X (X being the number the app icon will be badged with).


image.png
#Without Title:
{
  "aps":{
     "alert":{
      "body":"The value of the Body Notify parameter now goes here."
  }
}

#With Title:
{
  "aps":{
     "alert":{
      "body":"The value of the Body Notify parameter now goes here.",
      "title":"Now you can also receive title."
  }
}

普通的remote push notification

有提示(APP在后台或closed状态时,1,响一声,2,手机上方出现横幅,3,消息显示在通知中心) 时,推送payload格式:

{
    "aps":{
        "alert": {
            "body": "hello",
            "title": "You have a new message"
        },
        "sound": "default",
        "badge": 1
    },
    "custom1": "custom information"
}

静默推送

silent push要求push payload必须满足下面两点:

1) The payload’s aps dictionary must include the content-available key with a value of 1.
必须有"content-available",且值为1;
2) The payload’s aps dictionary must not contain the alert, sound, or badge keys.
一定不能包含alert,sound 和 badge

当用户设备收到silent push后,它会在后台调起app并运行30秒,调用的delegate:

application:didReceiveRemoteNotifiacation:fetchCompletionHandler:
与收到普通remote push notification后,在通知中心(或横幅)点消息后,调起APP,系统调用的delegate一致。

但是开启silent push,必须给APP设置相应的capability:

在Xcode中,工程Targets->Capabilities->Background Modes 设置为ON,并且勾选 Remote notifications
但是需要注意的一点,在guide中也被标记为IMPORTANT,silent push不是用来保持APP在后台awake的,也不具有高优先级。APNs把silent push视为低优先级,并且如果消息总数过多,可能会限制其传送。实际的限制是动态且根据具体情况变化的,但是请不要在一小时内传送过多的数据。

但是,更重要的一点是,APP收到silent push后,调用delegate的前提条件是APP没有被杀死,比如:用户手动划走,被系统回收或者手机重启。在这3种情况下,silent push并不能唤醒APP并执行一段代码。

目标推送以及群推

image.png

相关文章

  • React-Native 消息推送

    在这里我们可以选择大厂的推送,优先使用极光推送,下一篇将介绍如何使用阿里推送。 使用说明 PS: 真没想到极光大厂...

  • react-native 消息推送

    ios新建推送以及开发证书部分(略去) 创建私钥 Strip anything outside of "-----...

  • React-Native 消息推送--Android混合推送

    背景 由于使用任何一种Android推送都很难在APP进程被杀死后收到推送,只有集成各厂商提供的系统级别推送才能完...

  • expo react-native 消息推送

    今天有个巴基斯坦友人求助expo消息推送,之前国内一直用极光之类,所以类似expo推送之前还真没接触过,对方把项目...

  • Android - React-native在原生MainAct

    React-native在MainActivity中发送消息给前端 目前,一些App都会集成推送的功能,很多需求中...

  • React-Native 学习之路 - 极光消息推送Could

    在0.55 .4 中错误:Could not find method api() for arguments [d...

  • 消息推送

    推送通知的呈现效果总结 推送通知有5种不同的呈现效果1、在屏幕顶部显示一块横幅(显示具体内容)2、在屏幕中间弹出一...

  • 消息推送

    1、.简述一下消息推送的流程 2、如果不依赖APNS,如何在App进入后台时保证能够接收到远程消息?

  • 消息推送

    推送概念? APNs:Apple Push Notification Service,远程通知只能APNs服务器发...

  • 消息推送

    本地推送 @implementation AppDelegate 远程推送http://blog.csdn.net...

网友评论

      本文标题:react-native 消息推送

      本文链接:https://www.haomeiwen.com/subject/clopxltx.html