Google / Apple推送通知服务(APNS / GCM)

时间:2021-07-13 02:19:36

I'm trying to create application for Android and iOS and I want to use push notification on both the application. I'm going to have a server app that will be sending the notification.

我正在尝试为Android和iOS创建应用程序,我想在应用程序上使用推送通知。我将要一个将发送通知的服务器应用程序。

What I'm trying to figure out is how we can store the device of the user so I'll know which service need to be used APNS or GCM.

我想弄清楚的是我们如何存储用户的设备,以便我知道哪些服务需要使用APNS或GCM。

One of the directions is to get the phone type to be set by the app and store this information on the server side, but what happens if the user changes his phone from iOS to Android, need to involve data storage of the user and collect information for every user, not covers scenario when user has Android tablet and iOS phone.

其中一个方向是让应用程序设置手机类型并将此信息存储在服务器端,但如果用户将手机从iOS更改为Android,需要涉及用户的数据存储并收集信息会发生什么情况对于每个用户,不包括用户拥有Android平板电脑和iOS手机的情况。

Make it more generic and dispatch the notification to both services APNS and GCM at the same time, one of them will return error?

使它更通用,同时将通知发送给服务APNS和GCM,其中一个会返回错误?

Would love to hear what is the best practice for such scenarios?

很想听听这种场景的最佳做法是什么?

2 个解决方案

#1


27  

It is very simple to implement APNS and GCM:

实现APNS和GCM非常简单:

  • When APNS (iOS Devices) and GCM (Android Device) registers for Push Notification on Apple and Google Server it generates a unique token for every device.
  • 当APNS(iOS设备)和GCM(Android设备)在Apple和Google Server上注册推送通知时,它会为每个设备生成唯一令牌。

  • After that, you need to save that device token, with your device id or user id (unique id on your server for device) and the OS of device.
  • 之后,您需要使用您的设备ID或用户ID(设备服务器上的唯一ID)和设备操作系统保存该设备令牌。

Like and iOS device is sending this information on your server (backend) you can use this JSON format- {"token":"abcdedfgehik2bd3d3ff3sffssdff","os":"iOS","userid":34}

喜欢和iOS设备在您的服务器(后端)上发送此信息,您可以使用此JSON格式 - {“token”:“abcdedfgehik2bd3d3ff3sffssdff”,“os”:“iOS”,“userid”:34}

For android device it will be - {"token":"erydnfbdbdjskd76ndjs7nnshdjs","os":"Android","userid":35}

对于Android设备,它将是 - {“token”:“erydnfbdbdjskd76ndjs7nnshdjs”,“os”:“Android”,“userid”:35}

By this you can identify the OS of device, as well as user information and unique token which will be used for sending push notification.

通过这种方式,您可以识别设备的操作系统,以及用于发送推送通知的用户信息和唯一令牌。

#2


3  

when the device registers with the push service you could create a Unique id (UUID) and then send the unique id to the server along with the registration key and any other information you want. That way you have all the devices the use has and dispatch notifications to all of them

当设备向推送服务注册时,您可以创建唯一ID(UUID),然后将唯一ID与注册密钥和您想要的任何其他信息一起发送到服务器。这样您就可以使用所有设备并向所有设备发送通知

#1


27  

It is very simple to implement APNS and GCM:

实现APNS和GCM非常简单:

  • When APNS (iOS Devices) and GCM (Android Device) registers for Push Notification on Apple and Google Server it generates a unique token for every device.
  • 当APNS(iOS设备)和GCM(Android设备)在Apple和Google Server上注册推送通知时,它会为每个设备生成唯一令牌。

  • After that, you need to save that device token, with your device id or user id (unique id on your server for device) and the OS of device.
  • 之后,您需要使用您的设备ID或用户ID(设备服务器上的唯一ID)和设备操作系统保存该设备令牌。

Like and iOS device is sending this information on your server (backend) you can use this JSON format- {"token":"abcdedfgehik2bd3d3ff3sffssdff","os":"iOS","userid":34}

喜欢和iOS设备在您的服务器(后端)上发送此信息,您可以使用此JSON格式 - {“token”:“abcdedfgehik2bd3d3ff3sffssdff”,“os”:“iOS”,“userid”:34}

For android device it will be - {"token":"erydnfbdbdjskd76ndjs7nnshdjs","os":"Android","userid":35}

对于Android设备,它将是 - {“token”:“erydnfbdbdjskd76ndjs7nnshdjs”,“os”:“Android”,“userid”:35}

By this you can identify the OS of device, as well as user information and unique token which will be used for sending push notification.

通过这种方式,您可以识别设备的操作系统,以及用于发送推送通知的用户信息和唯一令牌。

#2


3  

when the device registers with the push service you could create a Unique id (UUID) and then send the unique id to the server along with the registration key and any other information you want. That way you have all the devices the use has and dispatch notifications to all of them

当设备向推送服务注册时,您可以创建唯一ID(UUID),然后将唯一ID与注册密钥和您想要的任何其他信息一起发送到服务器。这样您就可以使用所有设备并向所有设备发送通知