question

mflorin avatar image
mflorin asked

No sound for iOS Push Notifications,

I have setup push notifications for iOS, and the notifications work just fine, except there is no sound or vibration when the message arrives.

Sounds are enabled for my game in iOS notification settings, and I do get a sound when receiving notifications for other apps. I have tested both on iPhone and iPad.

I am registering for notifications like this:

UnityEngine.iOS.NotificationServices.RegisterForNotifications( 
  UnityEngine.iOS.NotificationType.Alert | 
  UnityEngine.iOS.NotificationType.Badge | 
  UnityEngine.iOS.NotificationType.Sound, 
  true); 

I am sending the notification like this:

server.SendPushNotification({ 
    "Recipient": args.playfabId, 
    "Message": args.name + " has challenged you to a match!" 
});

Any idea what the issue might be?

TIA

,

Push Notifications
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
marcowilliamspf avatar image
marcowilliamspf answered

Hi, so I honestly didn't know the answer to this question and I had to look it up.

Here is a reference that I found that explains how to set the sound for the notification.
https://stackoverflow.com/questions/42273219/unity-for-ios-push-notification-has-no-sound?rq=1

It appears that you have to add this code locally for iOS

iOSNotification.soundName = LocalNotification.defaultSoundName;
iOSNotification.alertAction = "Alert Action";
iOSNotification.hasAction = true;

Per the suggested on StackOverflow thread.

By default, we do not pass any information that explicitly tells unity to set badges or notification sounds for iOS.


Hope that helps!

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mflorin avatar image mflorin commented ·

Hi, this answer appears to be for Local Notifications:

https://docs.unity3d.com/ScriptReference/iOS.LocalNotification.html

However if I am correct, the notifications I receive through Playfab are Remote Notifications, which fields are read-only:

https://docs.unity3d.com/ScriptReference/iOS.RemoteNotification.html

0 Likes 0 ·
mflorin avatar image mflorin mflorin commented ·

I figured it out. If I use Package like this it plays the default sound:

server.SendPushNotification({
      
  Recipient: args.playfabId,
    Package : {
        Title: "title",
    	Message : "the message",
        Sound: "default"
    }
  });

I had tried using Package before but received a blob of JSON in the message body. After clicking "Upgrade" on the Push Notification Settings page it works correctly.

The dialog that shows when clicking the "Upgrade" button only mentions Android FCM, it isn't very clear that it also upgrades iOS Notifications.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.