1

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!");
                }
            }];
user3808735
  • 25
  • 1
  • 6

3 Answers3

3

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
));
Darklex
  • 159
  • 6
1

Try this:

PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
NSDictionary *data = @{
                       @"badge": @"Increment",
                       @"alert": message,
                       @"sound": @"default"
                       };
[push setData:data];
[push sendPushInBackground];
Hsm
  • 1,510
  • 17
  • 16
0

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"
                      };
Mike
  • 9,765
  • 5
  • 34
  • 59
  • thanks a lot for the response Mike. Unfortunately this neither creates generates a sound nor updates my badge. Would you happen to know what else could be the issue? – user3808735 Aug 22 '14 at 23:07
  • check her for incrementing the badge http://stackoverflow.com/questions/11153631/increment-the-push-notification-badge-iphone. Referring to the sound, have you tried dropping in a test .wav file and putting that there. Also, dumb question I know, but is the phone on vibrate? – Mike Aug 22 '14 at 23:18
  • yes I did both those things and for whatever reason there's no sound or badge being updated. Thanks a lot for your help though. – user3808735 Aug 22 '14 at 23:35
  • Do you get the notification? – Mike Aug 22 '14 at 23:35
  • yes I get the notification, but there is no sound and no badge. – user3808735 Aug 22 '14 at 23:45
  • Try @1 for the badge and tell me if the badge updates – Mike Aug 22 '14 at 23:46
  • Are you testing this with the app open or backgrounded? – Mike Aug 22 '14 at 23:50
  • I've tested for both and they both give me a push notification but no sound and no badge update. – user3808735 Aug 22 '14 at 23:53
  • NSLog the push notification info in didReceiveRemoteNotification – Mike Aug 22 '14 at 23:55
  • It doesn't appear that function is being called. However, I did try sending a push notification directly through the parse server and the notification does come with a sound. My guess is that this would mean I'm doing something wrong when sending the actual push notification in my code. – user3808735 Aug 23 '14 at 00:34
  • Unfortunately, I don't have any experience with Parse so I can't help there. – Mike Aug 23 '14 at 00:34