无论出于何种原因,我收到推送通知时都无法发出默认声音,也不会在收到时更新徽章编号。这是我的代码,如下所示。你认为我的代码有问题吗?或者是否存在我不知道的配置问题?谢谢你的帮助!
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"installationUser" containedIn:recipients];
// Send push notification to our query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
message, @"alert",
@"Increment", @"badge",
nil];
[push setData:data];
[push setMessage:[NSString stringWithFormat:@"%@ sent you a photo!", currentUser.username]];
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(!error)
{
NSLog(@"Push notification sent!");
}
}];
答案 0 :(得分:3)
同样的事情发生在我身上,但我使用PHP SDK并以正确的方式发送它是这种形式。在$ data中,您需要将要发送的内容写入NSDictionary userinfo。
$data = array("alert" => "Your message", "badge" => "Increment", "sound" => "default");
$query = ParseInstallation::query();
$query->equalTo("deviceToken", $devicetoken);
ParsePush::send(array(
"where" => $query,
"data" => $data
));
答案 1 :(得分:1)
试试这个:
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
NSDictionary *data = @{
@"badge": @"Increment",
@"alert": message,
@"sound": @"default"
};
[push setData:data];
[push sendPushInBackground];
答案 2 :(得分:0)
根据我使用推送通知的经验,而不是Parse,不包括推送有效负载中的声音键/值将使推送静音。尝试将带有一些随机值的声音添加到字典中,如下所示并尝试一下。此外,还有一种更好/更清晰的方法来创建NSDictionary:
NSDictionary *data = @{
@"badge": @"Increment",
@"alert": message,
@"sound": @"nothing"
};