我有一个使用GCM推送通知的应用程序。 它工作正常,我的设备寄存器和接收推送消息。
如果我卸载从我的设备应用程序,我不再收到消息如你所愿。 在你的服务器上发送短信的文本框是仍然存在后,我未安装的应用程序,这也是我所期待。
我看了看文档中有关取消注册,您可以手动或自动做到这一点。
The end user uninstalls the application.
The 3rd-party server sends a message to GCM server.
The GCM server sends the message to the device.
The GCM client receives the message and queries Package Manager about whether there are broadcast receivers configured to receive it, which returns false.
The GCM client informs the GCM server that the application was uninstalled.
The GCM server marks the registration ID for deletion.
The 3rd-party server sends a message to GCM.
The GCM returns a NotRegistered error message to the 3rd-party server.
The 3rd-party deletes the registration ID.
我不明白,在上面的列表中的倒数第二个发言。
The GCM returns a NotRegistered error message to the 3rd-party server.
这是怎样来达到的?
此外,如果应用被卸载设备,这可怎么办下面的语句? 有作为一个应用程序从设备中移除,其执行一个应用程序的生命周期方法? 如果有,这就是代码放置在该通知卸载和调用第三方服务器将删除数据库中的RegID在PHP脚本的GCM服务器的地方吗?
The GCM client informs the GCM server that the application was uninstalled.
提前致谢,
马特
[edit1]
static void unregister(final Context context, final String regId) {
Log.i(TAG, "unregistering device (regId = " + regId + ")");
String serverUrl = SERVER_URL + "/unregister.php";
Map<String, String> params = new HashMap<String, String>();
params.put("regId", regId);
try {
post(serverUrl, params);
GCMRegistrar.setRegisteredOnServer(context, false);
String message = context.getString(R.string.server_unregistered);
CommonUtilities.displayMessage(context, message);
} catch (IOException e) {
// At this point the device is unregistered from GCM, but still
// registered in the server.
// We could try to unregister again, but it is not necessary:
// if the server tries to send a message to the device, it will get
// a "NotRegistered" error message and should unregister the device.
String message = context.getString(R.string.server_unregister_error,
e.getMessage());
CommonUtilities.displayMessage(context, message);
}
}
[EDIT2]下面的注销码是用于从电话删除应用程序后注销第三方服务器上的设备。 该代码是除了下面的教程。
教程
send_messages.php
<?php
if (isset($_GET["regId"]) && isset($_GET["message"])) {
$regId = $_GET["regId"];
$message = $_GET["message"];
$strRegID = strval($regId);
include_once './GCM.php';
include_once './db_functions.php';
$gcm = new GCM();
$registatoin_ids = array($regId);
$message = array("price" => $message);
$result = $gcm->send_notification($registatoin_ids, $message);
$db = new db_Functions();
if (strcasecmp ( strval($result) , 'NotRegistered' )) {
$db->deleteUser($strRegID);
}
}
?>
db_functions.php
public function deleteUser($regid) {
$strRegID = strval($regid);
$serverName = "LOCALHOST\SQLEXPRESS";
$uid = "gcm";
$pwd = "gcm";
$databaseName = "gcm";
$connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>$databaseName);
$db = sqlsrv_connect($serverName,$connectionInfo) or die("Unable to connect to server");
$query = "DELETE FROM gcmUser2 WHERE gcuRegID = '$regid'";
$result = sqlsrv_query($db, $query);
}