迅速的本地通知声音不起作用

时间:2018-06-02 01:55:36

标签: ios iphone swift unusernotificationcenter

我在iOS上尝试了带声音的本地通知。

let content = UNMutableNotificationContent()
content.title = "Intro to Notifications"
content.subtitle = "Lets code,Talk is cheap"
content.body = "Sample code from WWDC"
content.sound = UNNotificationSound(named: "out.caf")

// content.sound = UNNotificationSound(named: "out.caf")

let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5.0, repeats: false)
let request = UNNotificationRequest(identifier:self.peripheralUUID, content: content, trigger: trigger)

UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request){(error) in

    if (error != nil){

        print(error?.localizedDescription)
    }
}        

声音不起作用,只有振动才有效。 有什么问题?

1 个答案:

答案 0 :(得分:0)

首先确保检查目标会员的文件并尝试此扩展程序

enter image description here

content.sound = UNNotificationSound(named: "out.aif")

还要确保持续时间< 30秒