繁体   English   中英

使用解析向特定用户发送推送通知

[英]Send push notification to specific user using Parse

我想使用PHP向特定用户发送推送通知。 我知道这个问题被问过很多次。 但是我的问题没什么不同。 就我而言,推送通知是发送给所有用户的,即使我已将其指定为向特定用户发送推送,

为此,每当用户在其Android设备上安装应用程序时,我都会在Parse.com的安装表中保存一个唯一ID。 这是android应用中的代码:

Parse.initialize(this, "XXXX", "XXXX");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("device_id", Secure.getString(getContentResolver(), Secure.ANDROID_ID));
installation.saveInBackground();

这很好。 我可以在解析的安装表中看到ID。

现在,这是我用来向特定设备ID发送推送通知的php脚本。 它确实将推送通知发送给所有用户。

require_once('autoload.php');

use Parse\ParseInstallation;
use Parse\ParsePush;
use Parse\ParseClient;

ParseClient::initialize( 'XXXXXX', 'XXXXX', 'XXXXX' );

function sendPush($query){
    $notification = "Test notification!";
    $data = array("alert" => $notification);
    ParsePush::send(array(
        "where" => $query,
        "data" => $data
    ));
}

$query = ParseInstallation::query();
$query->equalTo("device_id", "XXXXXX");
sendPush($query);

在寻找了很多解决方案之后,我检查了他们的github问题页面,在“已解决的问题”部分中,我发现了一个类似的问题 解决方案是仅更新SDK。 因为他们在ParsePush.php中打了错字。 因此,如果任何人遇到此问题,请更新您的Parse PHP SDK

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM