我有一个要求,例如,我们要通过应用程序设置通知声音和音量。这是因为我们的要求。有三种不同的状态——快乐、悲伤和正常。当用户获得一些积分时,我们会发送祝贺信息,当他失去一些积分时,我们也会发送该信息。促销也与其他一些信息有关。对于所有这些状态,我也想设置不同的通知声音和音量。感谢您的投入。泰
最佳答案
用于本地通知
func scheduleNotifications(inSeconds: TimeInterval, completion: @escaping (_ Success: Bool) ->()){
...
notif.sound = UNNotificationSound.init(named: "CustomSound.mp3")
...
}
对于推送通知
APS数据中应该有声音 key ,你的服务器需要发送要播放的文件名,
{
aps =
{
alert = "message";
sound = "sound file name.extension";
badge = 1;
};
}
关于iOS : Programmatically control the volume of Notification alert and sound theme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43270062/