js_55 js_55 - 5 months ago 43
iOS Question

iOS push notifications does not play sound and does not show badge alert [in Objective C]

I was using the demo instructions provided here:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/

here is the main code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);


UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

return YES;
}

-(void)MessageBox:(NSString *)title message:(NSString *)messageText
{
// OLD way of sending push notifications:

// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:messageText delegate:self
// cancelButtonTitle:@"OK" otherButtonTitles: nil];
// [alert show];


UIAlertController* alert= [UIAlertController
alertControllerWithTitle:title
message:messageText
preferredStyle:UIAlertControllerStyleAlert];


UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];

[alert addAction:defaultAction];
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];

}


I get notifications to appear, however there is not sound and badge update.
Any suggestions?

Answer

Have you included the badge and sound parameters in your JSON payload?

EXAMPLE

{"aps":{"alert":"Example notification title","badge":1,"sound":"default"}}

I'd read up on the Apple Push Notification Payload Documents to familiarise yourself.