我在验证GCM令牌时有点困惑。我使用Sencha框架在跨平台应用程序中工作,我的服务器端使用Java。我有一个关于如何验证注册ID (GCM令牌)的查询?是否有特定的API来验证GCM令牌?你能指导我如何在客户端或服务器端处理这个问题吗?我已经在服务器端完成了注册部分,用户可以在数据库中注册他们的GCM令牌。现在我需要验证这个注册令牌。
每两周注销一次应用程序是一种好方法吗?
发布于 2013-10-01 09:45:21
用canonicalID 链接解决GCM验证问题的解决方案
private void asyncSend(List<String> partialDevices) {
// make a copy
final List<String> devices = new ArrayList<String>(partialDevices);
threadPool.execute(new Runnable() {
public void run() {
Message message = new Message.Builder().build();
MulticastResult multicastResult;
try {
multicastResult = sender.send(message, devices, 5);
} catch (IOException e) {
logger.log(Level.SEVERE, "Error posting messages", e);
return;
}
List<Result> results = multicastResult.getResults();
// analyze the results
for (int i = 0; i < devices.size(); i++) {
String regId = devices.get(i);
Result result = results.get(i);
String messageId = result.getMessageId();
if (messageId != null) {
logger.fine("Succesfully sent message to device: " + regId +
"; messageId = " + messageId);
String canonicalRegId = result.getCanonicalRegistrationId();
if (canonicalRegId != null) {
// same device has more than on registration id: update it
logger.info("canonicalRegId " + canonicalRegId);
Datastore.updateRegistration(regId, canonicalRegId);
}
} else {
String error = result.getErrorCodeName();
if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
// application has been removed from device - unregister it
logger.info("Unregistered device: " + regId);
Datastore.unregister(regId);
} else {
logger.severe("Error sending message to " + regId + ": " + error);
}
}
}
}});
}发布于 2013-09-25 14:14:29
您在客户端从GCM注册到GCM并取消注册。这就是你从谷歌那里获得注册ID的地方。
一旦您有了注册ID,您应该认为它是有效的,直到:
我认为每两周不注册一次应用程序是没有意义的。谷歌的代码示例只在安装了新版本的应用程序后才重新注册,即使在重新注册之前,它们也不会取消注册。
https://stackoverflow.com/questions/18997183
复制相似问题