我在我的Web服务器上运行一个PHP/MySQL应用程序,我需要向iOS设备发送推送通知。
实现这个的最简单方法是什么?有没有我可以使用的PHP库?还是甚至有任何服务提供商在其中与APNS服务器进行交互呢?
你有什么经验?使用PHP实现推送通知需要多少工作量?
我在我的Web服务器上运行一个PHP/MySQL应用程序,我需要向iOS设备发送推送通知。
实现这个的最简单方法是什么?有没有我可以使用的PHP库?还是甚至有任何服务提供商在其中与APNS服务器进行交互呢?
你有什么经验?使用PHP实现推送通知需要多少工作量?
Choose a Saas API that you will connect to your PHP/MySQL Application
Upload users
I really recommend to use the SDK proposed by those services because the job they make is significant. They import user devices ID, with other informations such as app opens, behavior events... all you can use for segmenting your user base. Moreover, SDKs are the only way to display rich and in-app messages, and to track conversion.
But if you really want to do without SDK, you can.
For example with WonderPush Notifications API, because I know this one, you have to make the two following calls. You need first to login (it takes one second, it doesnt required credit card !) create your app and grab your client id.
Then for each device, you just need to make the two following requests:
curl -XPOST https://api.wonderpush.com/v1/authentication/accessToken \
-d clientId=YOUR_APP_CLIENT_ID \
-d devicePlatform=iOS \
-d deviceId=DEVICE_ID
curl -XPATCH https://api.wonderpush.com/v1/installation \
-d accessToken=TOKEN_FROM_PREVIOUS_CALL \
-d body='{"pushToken":{"data":{"DEVICE_PUSH_TOKEN"}}}'
Notify your users
This example is just for simple notification. You can go further with many advanced features, like HTML in app messages, custom events...
curl -XPOST https://api.wonderpush.com/v1/management/deliveries \
-d accessToken=SERVER_PRIVATE_ACCESS_TOKEN \
-d applicationId=YOUR_APP_ID \
-d segmentIds=@ALL \
-d notificationOverride='{"type":"simple","text":"Hello, that's my message!","data":{"type":"simple"}}'
关于托管APNS服务的问题之前已经有了一个问题;然而,其中一些服务现在似乎已经关闭。
目前有两个服务:Urban Airship和iLime。两者都提供免费服务,直到达到一定数量的消息为止。我还没有使用过任何一个,所以无法评论它们的工作效果,但我知道Urban Airship自APNS早期就存在,这让人感到有点安心。