1

我正在为一个非常关心用户数据隐私的客户开发一个 Android 应用程序。

WonderPush Android SDK是开源的,但我想在不升级 Google Play 应用程序的情况下进行几次测试。

那么,是否可以仅使用 WonderPush REST API 将推送通知发送到设备而不使用其 SDK?

4

1 回答 1

2

Everything that the SDK does can be done without it, though using the SDK will greatly simplify the developer's life. It is especially easy to mock the SDK as it is open source and available on GitHub, and the REST API is documented.

You can also test your application in the simulator or on your own devices, there is no need to deploy the new version of your WonderPush-enabled application to experiment with it.

Push notifications can either be sent using your dashboard or using the REST Management API. The SDK is in charge of registering the application for push notification reception, collecting users and registering them on WonderPush, and displaying the received push notifications to the user.


1a. If your application is not registered to receive push notifications

You will need to follow the following two guides:

In your BroadcastReceiver, simply get the alert extra string field using intent.getExtras().getString("alert") then format and display a notification using the NotificationManager.

1b. If your application is already push notifications ready

Unlike iOS, the Android platform does not define any official fields in a push notification, which is just an arbitrary JSON object. When sending your push notification you are interested mainly in how the application will present it to the user. As there is no standard, every provider does a different thing.

So you will want to make sure the push notification you send uses the format your application (including any SDK you might already be using) is ready to accept.

WonderPush uses the alert field to store the message to be displayed in the notification center in the user's device. Any rich (alert dialog box, html, map, etc.) notification configuration won't work out-of-the-box without the WonderPush SDK, because there is no standard. If the alert field does not suit you, you'll need to fill the "Payload override" in the notification form. You can also use the Management REST API to easily push custom notifications on the fly.

2. Import users in WonderPush

In order to send push notifications to your users' devices, WonderPush must know about them. You hence need to import your users by creating an installation object for each of them. The installation identifies an instance of your app, installed on a user's device. The key part is to provide WonderPush with the registrationId, called push token in our lingo.

curl -XPOST https://api.wonderpush.com/v1/authentication/accessToken \
    -d clientId=YOUR_APP_CLIENT_ID \
    -d devicePlatform=iOS \
    -d deviceId=FOOBAR

curl -XPATCH https://api.wonderpush.com/v1/installation \
    -d accessToken=TOKEN_FROM_PREVIOUS_CALL \
    -d body='{"pushToken":{"data":{"DEVICE_PUSH_TOKEN"}}}'

3. Send push notifications

Push notifications can either be sent using your dashboard, or using the REST Management API as follows:

curl -XPOST https://management-api.wonderpush.com/v1/deliveries \
    -d accessToken=SERVER_PRIVATE_ACCESS_TOKEN \
    -d applicationId=YOUR_APP_ID \
    -d targetSegmentIds=@ALL \
    -d notification='{"alert":{"text":"Hello, WonderPush!"}}'
于 2015-02-10T14:24:26.600 回答