推送通知,令牌过期?

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

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

这个令牌总是一样的? 如果得到一次令牌,我需要检查令牌是否改变?

从苹果文档,

令牌信任阶段的forms确保只有APN生成它将在后面兑现的令牌,并且可以确保设备递交给它的令牌与先前为该特定设备预configuration的令牌相同该设备。

如果用户将备份数据恢复到新设备或重新安装操作系统,则设备令牌会更改。

所以,使用从APN收到的令牌来更新服务器总是很好的。 作为优化的一部分,如果您收到相同的标记,则不需要更新服务器。

对于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); ... }