通过 OneSignal 发送通知 - 如何启用声音

Send notification via OneSignal - how to enable sound

我正在使用以下代码通过 OneSignal 从用户向用户发送通知。它运作良好,除了我无法在收到通知时发出声音。有人知道我错过了什么吗?此代码取自他们位于 https://github.com/OneSignal/OneSignal-iOS-SDK

的示例项目
    let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState()
    let pushToken = status.subscriptionStatus.pushToken
    let userId = status.subscriptionStatus.userId


    if pushToken != nil {
        let message = "This is a notification's message or body"
        let notificationContent = [
            "include_player_ids": [userId],
            "contents": ["en": message], // Required unless "content_available": true or "template_id" is set
            "headings": ["en": "Notification Title"],
            "subtitle": ["en": "An English Subtitle"],
            // If want to open a url with in-app browser
            //"url": "https://google.com",
            // If you want to deep link and pass a URL to your webview, use "data" parameter and use the key in the AppDelegate's notificationOpenedBlock
            "data": ["OpenURL": "https://imgur.com"],
            "ios_attachments": ["id" : "https://cdn.pixabay.com/photo/2017/01/16/15/17/hot-air-balloons-1984308_1280.jpg"],
            "ios_badgeType": "Increase",
            "ios_badgeCount": 1,
            ] as [String : Any]

        OneSignal.postNotification(notificationContent)
    }

推送通知是有意从 iPad 发送到同一设备的。

有效负载中必须包含三个基本内容(alertbadgesound),否则它会在执行时丢失,示例有效负载应如下所示。 See Documentation

{
 “aps” : {
 “alert” : “Your message here.”,
 “sound” : “default”,
 “badge” : 9
 }
}

default关键字将播放通知的默认声音,您也可以播放自定义声音,如“sound” : “sound.wav”,

已编辑

在 Onesignal 中是这样 "ios_sound": "sound.wav" 播放自定义声音 see here

在 Onesignal 中您无法播放默认声音 see here

希望这会有所帮助。