我想在交互式本地通知中添加自定义声音 . 我在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秒 . 任何budy可以告诉我我错过了什么 .
3 回答
您不需要获得自定义声音的完整路径,只需要声音名称和文件格式
like notification.soundName = "notes_of_the_optimistic.caf"
这里的问题是您要将整个路径发送到您的声音资产 .
更换
同