Reputation: 101
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.
Upvotes: 0
Views: 627
Reputation: 1366
.caf and any manually type converted file will not work. use mp3 and aiff (apple define format).
Upvotes: -1
Reputation: 2446
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"
Upvotes: 1
Reputation: 7373
The issue here is that you are sending in the entire path to your sound asset.
Replace
let ring: String = NSBundle.mainBundle().pathForResource("notes_of_the_optimistic", ofType: "caf")!
with
let ring: String = "notes_of_the_optimistic"
Upvotes: 1