0

I am trying to set the local notification sound to my downloaded audio. But when notification trigger no sound is played. I don't know where i am going wrong. Please have a look on code and let me know my mistake.

func setNotificationWithDate(date: NSDate, onWeekdaysForNotify: [Int], snooze: Bool, soundName: String, title: String, vibrate: Bool) {


    let AlarmNotification: UILocalNotification = UILocalNotification()
    AlarmNotification.alertBody = title
    AlarmNotification.alertAction = "Open App"
    AlarmNotification.category = "AlarmCategory"
    AlarmNotification.timeZone = NSTimeZone.defaultTimeZone()

    let datesForNotification = correctDate(date, onWeekdaysForNotify:onWeekdaysForNotify)

    for d in datesForNotification
    {
        AlarmNotification.fireDate = d
        let tracksDic = appDelegate().alarmTrackArray.objectAtIndex(d.dayOfWeek()!)
        let sound = tracksDic.valueForKey("t_id") as? String
        AlarmNotification.soundName = sound! + ".mp3"
        print(AlarmNotification.soundName)
        let userInfo = ["date":date,"soundDetail":tracksDic,"title":title ,"vibrate":vibrate]
        AlarmNotification.userInfo = userInfo
        print(AlarmNotification.soundName)
        UIApplication.sharedApplication().scheduleLocalNotification(AlarmNotification)
    }
}
CouchDeveloper
  • 18,174
  • 3
  • 45
  • 67
PAn Kaj Khatri
  • 539
  • 1
  • 6
  • 22

1 Answers1

1

Make sure the sound is actually in your app’s bundle, is in the correct format (linear PCM or IMA4—pretty much anywhere that explains how to convert sounds for iOS will tell you how to do that), and is under 30 seconds.

Reference Link :

Choose custom sound for local notifications

Update according to your comment :

Downloaded file will not be in your bundle. so it will not play that sound!!!!

Community
  • 1
  • 1
Payal Maniyar
  • 4,293
  • 3
  • 25
  • 51
  • I am playing a mp3 file in the notification and its working fine. But when i am try to set the downloaded one the no sound will play. i have checked the apple notification sound property and i found that "public var soundName: String? // name of resource in app's bundle to play or UILocalNotificationDefaultSoundName" – PAn Kaj Khatri May 03 '16 at 10:07