I want to add custom sound in interactive localnotification. I have write this code in 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)
}
}
I have added notes_of_the_optimistic.caf file in my project but my nitification always give the default sound. The length of the sound file is 29sec. Can any budy tell me what I am missing.
You don't need get a full path of your custom sound, you need only sound name with file format like notification.soundName = "notes_of_the_optimistic.caf"