我想在交互式本地通知中添加自定义声音。我已经在appdelegate中编写了这段代码
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
scheduleNotification()
}
func scheduleNotification() {
//UIApplication.sharedApplication().cancelAllLocalNotifications()
// Schedule the notification ********************************************
if UIApplication.sharedApplication().scheduledLocalNotifications!.count == 0 {
let notification = UILocalNotification()
notification.alertBody = "Hey! Update your counters ;)"
// let URLToMyFile = documentsURL.URLByAppendingPathComponent("notes_of_the_optimistic.caf")
let ring: String = NSBundle.mainBundle().pathForResource("notes_of_the_optimistic", ofType: "caf")!
print(ring)
notification.soundName = ring
notification.fireDate = NSDate()
notification.category = categoryID
notification.repeatInterval = NSCalendarUnit.Minute
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
}
我在我的项目中添加了notes_of_the_optimistic.caf 文件,但我的 nitification 始终给出默认声音。声音文件的长度是29秒。有哪位 friend 可以告诉我我缺少什么吗?
最佳答案
您不需要获取自定义声音的完整路径,您只需要具有文件格式的声音名称 like notification.soundName = "notes_of_the_optimistic.caf"
关于ios - UILocalNotification 始终提供默认声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700842/