我正在联合开发iOS应用程序。我需要显示本地推送通知。
我使用下一个代码:
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
}
}当我调用ShowNotification时,通知会出现在notification中,但是没有任何声音和弹出。如何使我的通知正常显示?我接受了所有的许可(警报,声音,徽章)在发射。
测试设备: iPhone 4s,iOS 9.3.5
构建:团结5.4.4f1,XCode 8.2.1
发布于 2017-02-16 12:10:22
您需要放置此代码以播放声音并显示警报。
iOSNotification.soundName = LocalNotification.defaultSoundName;
iOSNotification.alertAction = "Alert Action";
iOSNotification.hasAction = true;发布于 2017-02-16 12:07:19
如果您想声音,您应该指定默认的声音名称。
iOSNotification.soundName = "default";添加这个,它将播放默认声音。
https://stackoverflow.com/questions/42273219
复制相似问题