我正在尝试将本地通知声音设置为我下载的音频。 但是当通知触发时没有播放声音。我不知道我哪里错了。请查看代码,让我知道我的错误。
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)
}
}
答案 0 :(得分:0)
确保声音实际上在您的应用程序包中,格式正确(线性PCM或IMA4 - 几乎任何解释如何转换iOS声音的地方都会告诉您如何操作),并且不到30秒
参考链接:
Choose custom sound for local notifications
根据您的评论更新:
下载的文件不在您的捆绑包中。所以它不会播放那种声音!!!!