【发布时间】:2016-06-13 10:17:05
【问题描述】:
我的本地通知正在工作,并且正在显示警报,但是没有播放声音。我正在设备上进行测试,因为我知道它不会在模拟器中播放。
let notificationAlert = UILocalNotification()
类 DailyAlarmViewController: UIViewController {
@IBOutlet weak var timePicker: UIDatePicker!
@IBAction func alarmSetButton(sender: AnyObject) {
notificationAlert.fireDate = timePicker.date
notificationAlert.timeZone = NSTimeZone.defaultTimeZone()
notificationAlert.repeatInterval = NSCalendarUnit.Day
notificationAlert.alertAction = "Open Survive to Thrive Nation!"
notificationAlert.alertBody = "Time to wake up and complete your Journal!"
notificationAlert.soundName = "Alarm_Clock.wav"
UIApplication.sharedApplication().scheduleLocalNotification(notificationAlert)
}
@IBAction func cancelAlarm(sender: AnyObject) {
UIApplication.sharedApplication().cancelLocalNotification(notificationAlert)
}
我需要添加背景模式或应用间音频吗?任何想法将不胜感激。
【问题讨论】:
-
您是否已将声音文件与项目资源捆绑在一起?如果您的应用找不到文件,它将不会播放声音。