Alexandre C. do Carmo Alexandre C. do Carmo - 1 year ago 101
PHP Question

Notification Sound and Badge don't work

I created a remote push notification, the notification works very well, but sound and badge don't work. In my server side code I have:

$messageBody['aps'] = array('alert' => $message, 'sound' => 'default','badge' => 2);

This the iOS code:

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {



func application(application: UIApplication, didReceiveRemoteNotificationuserInfo userInfo: [NSObject : AnyObject]) {

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
// Override point for customization after application launch.
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert, categories: nil))


return true


Why are sound and badge not working?

Answer Source

The php code looks alright. In the app, have you registered for pushnotifications? Also try to uninstall the app and then reinstall it and accept sounds and badges for the app.

EDIT: Also enable sounds and badges in your settings for your app.

EDIT 2: Try this: do: let types:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound] and then application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types, categories: nil)) You have to register the app for Alert, Sound and Badges but you only had registered for Alert.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download