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.

集成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来实现,我用的前者


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

绑定接口:

发送消息接口:

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

最终效果:

其他
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).

#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并执行一段代码。
目标推送以及群推

网友评论