Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Push Notification No Sound

Tags:

This is the code to register for push

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [application registerForRemoteNotifications];
}
else
{
    [application registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

It works fine as the app registers with the server.

The PEM files are also done correctly as I can send a push to my device using sandbox APNS.

When I print my JSON payload from didReceiveRemoteNotification I get this:

{
    aps =     {
        alert = "Test Push Message";
    };
}

The issue is when I receive my push (even when the device is set to loud) it doesn't play a sound.

From my knowledge, if you don't specify a sound in the JSON payload it should play the default OS sound.

In my App notification settings on the phone the sound is enabled by default because when I register I specify UIUserNotificationTypeSound.

Anyone else come across this issue?

like image 343
Omer Janjua Avatar asked Nov 17 '14 13:11

Omer Janjua


People also ask

Why are my iPhone notifications not making sound?

settings -> notifications -> (relevant app) -> customise notifications. ensure each account you want to have make a sound has alerts enabled. It has taken me days to get to this!

Why do I get notification but no sound?

Go to Settings. Select Sounds and Vibration. Tap Volume. Adjust the notifications slider to where you want it.

Can push notifications have sound?

On Android devices, it is possible to choose individual push notification sounds.


2 Answers

According to Apple's documentation you need to specify default if you want to the default push notification to be played:

The name of a sound file in the app bundle. The sound in this file is played as an alert. If the sound file doesn’t exist or default is specified as the value, the default alert sound is played. The audio must be in one of the audio data formats that are compatible with system sounds; see Preparing Custom Alert Sounds for details.

The final JSON output:

{
    "aps" :     {
        "alert" : "Test Push Message",
        "sound" : "default"
    };
}
like image 138
rckoenes Avatar answered Sep 19 '22 17:09

rckoenes


You should modify server JSON output to this. default it is sound type of the notification on your phone.

{
    "aps": {
        "alert": "test",
        "sound": "default"
    }
}
like image 40
Oleg Gordiichuk Avatar answered Sep 19 '22 17:09

Oleg Gordiichuk