user3808735
user3808735

Reputation: 25

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

Upvotes: 1

Views: 1809

Answers (3)

Hsm
Hsm

Reputation: 1540

Try this:

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

Upvotes: 1

Darklex
Darklex

Reputation: 159

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
));

Upvotes: 3

Mike
Mike

Reputation: 9835

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"
                      };

Upvotes: 0

Related Questions