我使用以下代码通过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发送到同一台设备。
答案 0 :(得分:1)
有效负载中有三个基本内容(alert
,badge
,sound
),否则它们必须在执行时丢失,示例有效负载应如下所示。 See Documentation
{
“aps” : {
“alert” : “Your message here.”,
“sound” : “default”,
“badge” : 9
}
}
default
关键字将播放默认的通知声音,您还可以播放自定义声音,如“sound” : “sound.wav”,
<强> EDITED 强>
在Onesignal中,"ios_sound": "sound.wav"
可以播放自定义声音see here
在Onesignal中,您无法播放默认声音see here
希望这会有所帮助。