简体   繁体   English

通过Parse发送推送通知时无声音

[英]No sound when sending push notifications through Parse

for whatever reason I cannot get my push notifications to make the default sound nor update the badge number when I receive them. 无论出于何种原因,我都无法收到推送通知以发出默认声音,也无法在收到通知时更新徽章编号。 Here's my code below. 这是我的下面的代码。 Do you think it's something wrong with my code? 您认为我的代码有问题吗? Or is there a configuration issue that I'm not aware of? 还是有我不知道的配置问题? Thanks for your help! 谢谢你的帮助!

            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!");
                }
            }];

The same was happening to me, but i using the PHP SDK and the correct way to send this is in this form. 我也发生了同样的事情,但是我使用的是PHP SDK,正确的发送方式是这种形式。 In the $data you need to write the things you are sending to the NSDictionary userinfo. 在$ 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
));

Try this: 尝试这个:

PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
NSDictionary *data = @{
                       @"badge": @"Increment",
                       @"alert": message,
                       @"sound": @"default"
                       };
[push setData:data];
[push sendPushInBackground];

From my experience with push notifications, not with Parse, not including the sound key/value in the push payload will make the push silent. 根据我对推送通知(而不是Parse)的经验,不将声音键/值包括在推送有效载荷中会使推送静音。 Try adding the sound with some random value to the dictionary like below and try it out. 尝试将具有某种随机值的声音添加到字典中,如下所示,然后尝试一下。 Also, there's a nicer/cleaner way to create an NSDictionary: 另外,还有一种更好/更干净的方法来创建NSDictionary:

NSDictionary *data = @{
                       @"badge": @"Increment",
                       @"alert": message,
                       @"sound": @"nothing"
                      };

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

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