【问题标题】:Unity for iOS push notification has no soundUnity for iOS 推送通知没有声音
【发布时间】:2017-07-05 12:30:25
【问题描述】:

我正在 Unity 中开发 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 时,通知会出现在通知面板中,但没有任何声音和弹出窗口。如何让我的通知正常显示?我在发布时接受了所有权限(警报、声音、徽章)。

测试设备:iPhone 4s、iOS 9.3.5

构建:Unity 5.4.4f1、XCode 8.2.1

【问题讨论】:

    标签: ios iphone unity3d


    【解决方案1】:

    您需要放置此代码才能播放声音并显示警报

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

    【讨论】:

      【解决方案2】:

      如果你想要声音,你应该指定默认的声音名称。

      iOSNotification.soundName = "default";
      

      添加这个,它会播放默认声音。

      【讨论】:

      • 感谢您的评论!
      猜你喜欢
      • 2015-01-14
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多