【问题标题】:iOS Local notifications - sound not playingiOS 本地通知 - 声音未播放
【发布时间】: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)      
}

我需要添加背景模式或应用间音频吗?任何想法将不胜感激。

【问题讨论】:

  • 您是否已将声音文件与项目资源捆绑在一起?如果您的应用找不到文件,它将不会播放声音。

标签: ios swift audio


【解决方案1】:

您必须检查 .wav 文件是否已添加到应用程序的资源中。

【讨论】:

    【解决方案2】:

    您可以尝试使用默认警报声音UILocalNotificationDefaultSoundName 来代替Alarm_Clock.wav。如果它有效,那么问题可能出在Alarm_Clock.wav

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多