GCM:如何从服务器向应用程序发送消息(丢失注册ID,通知ID ...) [英] GCM: How to send messages to apps from server (lost with registration ids, notification ids...)

查看:248
本文介绍了GCM:如何从服务器向应用程序发送消息(丢失注册ID,通知ID ...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我误解了一些东西。对不起。

I think I misunderstood something. Sorry for that.

我试图将推送讯息导入我的应用程式。

I'm trying to implement push messages to my app.


  1. 在GCM Web控制台(API Access)中,我添加了一个项目并检索了一个API密钥,

  1. In the GCM web console ("API Access") I've added a project and retrieved an API key which seems to the same for the whole project (whatever project means in this context) and a clientID ending with apps.googleusercontent.com for each of my apps.

然后,我将在下面的例子中看到。只需从google复制gcm-client示例,删除编译错误,添加libs并使其在手机上运行,​​而不是在模拟器上运行。
这里需要一个senderID,它似乎是来自API访问Url的projectid,对不对?

Then I simply copied the gcm-client example from google, removed the compiling errors, added the libs and made it run on phone, but not on the emulator. Here a senderID is required, which seems to be the "projectid" from the API access Url, right?

到目前为止,还不错。

服务器我需要一个API密钥。这是GCM API项目页面底部的一个(简单API访问)。此外,我需要一个registrationID。似乎是由我的应用程序在第一次运行计算,对吧?那么我需要将这个ID从我的应用程序复制到我的服务器吗?

For implementing the server I need an API key. This is the one out of the GCM API Project page at the bottom ("Simple API Access"). Furthermore I need a registrationID. Seems to be having calculated by my app at the very first run, right? So I need to copy this ID from my app into my server?

但是有没有办法直接通过GCM从我的应用程序检索registrationID? E.当我在应用商店中有我的应用时,如何获取下载我的应用的设备的ID?
对不起,但我对整个GCM机制感到困惑:(

But is there a way to retrieve the registrationIDs from my app directly via GCM? E. g. when I've got my app in the play store, how do I get the IDs of devices that downloaded my app? Sorry, but I'm kind of confused by the whole GCM mechanism :(

编辑:取消注册的过程如何工作我如何

How does the process of un-registration work. How do I learn, that a phone does not need any messages any more, what could happen under numerous various reasons?

推荐答案


  1. 服务器无法从GCM获取注册ID(除了在GCM的响应中获取规范注册ID的特殊情况之外,但为了使您的服务器必须已经知道旧的您的应用程序在该设备上使用的注册ID)。安装在设备上的应用程序的每个实例都必须向您的服务器发送注册ID,您的服务器应将这些ID保存在某些持久存储(DB,文件等)中。 。)。

  1. There is no way for the server to get the Registration IDs from GCM (except for the special case of getting Canonical Registration ID in a response from GCM, but in order to get that your server must already know the older Registration ID used by your app on that device). Each instance of your app, installed on a device, must send the Registration ID to your server, and your server should save these IDs in some persistent store (DB, file, etc...).

如果您的应用程式从GCM中取消注册,则可以通知您的伺服器未从GCM注册(类似于呼叫,您将向服务器发送注册ID),您的服务器将删除其注册ID。然而,更常见的情况是,应用程序通过从设备中卸载而是未注册的。在这种情况下,它无法通知您的服务器它已卸载。当您的服务器首次向卸载应用的设备发送通知时,它会获得成功的响应(因为GCM还不知道该应用已卸载),但随后尝试向该设备发送通知将导致 NotRegistered 错误,通知服务器删除相关的注册ID。

If your app un-registers from GCM explicitelly, it can notify your server that it un-registered from GCM (in a similar way to the call in which you send the Registration ID to the server), and your server will delete its Registration ID. However, the more common case is that the app is un-registered implicitelly by being uninstalled from a device. In that case it can't notify your server that it was uninstalled. When your server first sends a notification to a device from which the app was uninstalled, it will get a successfull response (since GCM doesn't know yet that the app was uninstalled), but later attempts to send notifications to that device will result in NotRegistered error, which tells the server to delete the relevant Registration ID.

这篇关于GCM:如何从服务器向应用程序发送消息(丢失注册ID,通知ID ...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆