推送通知,令牌过期?

时间:2014-06-16 12:45:31

标签: android ios push-notification token

我正在开发移动应用程序,而且我正在推送推送通知。

我可以从手机(苹果或Android)中检索令牌以发送推送,但我有一个问题:

此令牌始终相同?如果获得一次令牌,我需要检查令牌是否改变?

2 个答案:

答案 0 :(得分:2)

来自Apple文档,

  

此阶段信令的形式确保仅生成APN   它后来会尊重的标记,它可以保证一个   设备传递给它的令牌与之前的令牌相同   为该特定设备配置 - 仅适用于该设备。

     

如果用户将备份数据还原到新设备或重新安装   操作系统,设备令牌发生变化。

因此,使用从APN收到的令牌更新服务器总是好的。作为优化的一部分,如果您收到相同的令牌,则无需更新服务器。

答案 1 :(得分:1)

适用于Android:

这取决于您的实施,但谷歌推荐的是注册ID,可以在应用更新后更改...

每次更改注册ID时,客户端都应使用新值更新服务器。

检查:http://developer.android.com/google/gcm/client.html#sample-register

if (checkPlayServices()) {
        gcm = GoogleCloudMessaging.getInstance(this);
        regid = getRegistrationId(context);

        if (regid.isEmpty()) {
            registerInBackground();
        }
    } else {
        Log.i(TAG, "No valid Google Play Services APK found.");
    }

 private void registerInBackground() {
new AsyncTask() {
    @Override
    protected String doInBackground(Void... params) {
        String msg = "";
        try {
            if (gcm == null) {
                gcm = GoogleCloudMessaging.getInstance(context);
            }
            regid = gcm.register(SENDER_ID);
            msg = "Device registered, registration ID=" + regid;

            // You should send the registration ID to your server over HTTP,
            // so it can use GCM/HTTP or CCS to send messages to your app.
            // The request to your server should be authenticated if your app
            // is using accounts.
            sendRegistrationIdToBackend();

            // For this demo: we don't need to send it because the device
            // will send upstream messages to a server that echo back the
            // message using the 'from' address in the message.

            // Persist the regID - no need to register again.
            storeRegistrationId(context, regid);
        } catch (IOException ex) {
            msg = "Error :" + ex.getMessage();
            // If there is an error, don't just keep trying to register.
            // Require the user to click a button again, or perform
            // exponential back-off.
        }
        return msg;
    }

    @Override
    protected void onPostExecute(String msg) {
        mDisplay.append(msg + "\n");
    }
}.execute(null, null, null);
...
}
相关问题