0
votes

I'm developing iOS application in Unity. I need to show Local Push Notifications.

I use the next code:

public class TestNotification : MonoBehaviour {

    void Start(){
        UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound);
    }

    public void ShowNotification(){
    #if UNITY_IOS
        var iOSNotification = new UnityEngine.iOS.LocalNotification();
        iOSNotification.alertBody = "Hello!";
        UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(iOSNotification);
    #else
        Debug.LogError("Platform is not supported.");
    #endif
    }
}

When I call ShowNotification, notification appears in Notification Panel, but without any sound and popup. How to make my notifications show normally? I accepted all permissions(alert, sound, badge) on launch.

Testing Device: iPhone 4s, iOS 9.3.5

Build: Unity 5.4.4f1, XCode 8.2.1

2

2 Answers

0
votes

If you wan sound, you should specify default sound name.

iOSNotification.soundName = "default";

Add this, and it will play default sound.

0
votes

You need to place this code in order to play sound and display alert

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