我想在交互式localnotification中添加自定義聲音。我在的appdelegateUILocalNotification總是給出默認聲音
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都可以告訴我我錯過了什麼。
你並不需要得到你的自定義聲音的完整路徑,你需要像'notification.soundName =「notes_of_the_optimistic.caf」' – iSashok
它的工作文件格式只有聲音的名字,謝謝 – Avim
@iSashok請加作爲Avinash可以接受的答案。如果你們這樣做,其他用戶也將在未來得到幫助。 –