No sound when sending push notifications through Parse

强颜欢笑 提交于 2020-01-15 10:12:29

问题


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

回答1:


The same was happening to me, but i using the PHP SDK and the correct way to send this is in this form. In the $data you need to write the things you are sending to the 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
));



回答2:


Try this:

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



回答3:


From my experience with push notifications, not with Parse, not including the sound key/value in the push payload will make the push silent. 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 *data = @{
                       @"badge": @"Increment",
                       @"alert": message,
                       @"sound": @"nothing"
                      };


来源:https://stackoverflow.com/questions/25452560/no-sound-when-sending-push-notifications-through-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!