简体   繁体   中英

swift local notification sound not working

I tried local notification with sound on 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)
    }
}        

Sound not working, only vibrate is working. What is wrong?

First make sure that target memebership is checked for the file and also try this extension

在此处输入图片说明

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

also make sure duration is < 30 seconds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM