一台服务器向 Android 和 iOS 设备发送推送通知

问题描述:

我们的组织有一个 Android 应用和一个 iOS 应用.

Our organization has an Android app and an iOS app.

我们想开始向这些应用推送通知.

We want to start pushing notification to these apps.

Android 有 GCM.苹果有APNS.

Android has GCM. Apple has APNS.

但我们想要创建一个适用于 Android 和 iOS 的 API.

But we want to create an API which will work on both android and iOS.

设置服务器的最简单方法是什么,以便在需要发送推送通知时,它确切知道将消息发送到哪个服务器?

What is the easiest way to setup a server so that when a push notification needs to be sent, it knows exactly which server to send the message to?

作为一个小背景,这是一个大学环境,多个学院应用程序以及远程教育可能正在使用该服务.这是我们在组织中使用的方法.如果您查看 APNS 的工作方式,只需使用令牌 ID 向 APNS 服务发送 Web 调用即可使用它.GCM 非常接近同类型的系统.基本上创建一个 JSON 包并将其发送到所需的服务.

As a little background this is for a university setting where multiple colleges apps as well as distance education may be using the service. Here is the approach that we are using in our organization. If you look at the way APNS works it can be used by just sending a web call to the APNS service with the token id. GCM is very close to the same type of system. Basically create a JSON package and send it to the desired service.

这是我们用来创建此服务的步骤.

Here is our steps we used to create this service.

  1. 服务器管理员创建了一个可以调用的服务器和数据库,该数据库将从 android 和 ios 设备收集令牌.当设备注册时,我们还会发送它是什么类型的设备.这是可能的,因为我们只是将数据发送到已创建的数据库.

  1. Server admins created a server and database that can be called that will collect the tokens from both android and ios devices. When the device registers we also send what type of device it is. This is possible since we are just sending data to the database that is has been created.

然后我们从这里创建了几个 python 脚本,它们发送数据来执行所需的服务,无论是 ios 还是 android.这些脚本从数据库中收集适当的数据,并将打包的数据(JSON 包)发送到 APNS 用于 ios 消息和 GCM 用于谷歌云.

From here we then created a couple of python scripts that send the data do the desired service whether it is ios or android. These scripts gather the appropriate data from the database and sends the packaged data (JSON package) to APNS for ios message and GCM for google cloud.

我们还创建了一个网络界面,以便需要向设备发送消息的人可以.

We also created a web interface so that those who need to send messages to the devices can.

实施的其余部分由您决定使用服务的最佳方式.例如,何时检查无效设备,因为我们计划将同一台服务器用于多个应用程序,所以我们可以发送设备类型、令牌、应用程序或应用程序所需的任何其他内容,以将其与我们生产的其他应用程序区分开来,以便每个想要使用该服务的应用程序都可以.我希望这会有所帮助,并让您对如何实现这一目标有所了解.

The rest of the implementation is up to you to decide the best way to utilize the service. For example when to check for invalid devices, Because we are planning on using this same server for multiple applications we can send the type of device, token, application, or whatever else is needed for an application to distinguish it from others we produce so that each application that wants to use the service can. I hope this helps and gives you some idea on how to accomplish this.