【问题标题】:NSNotification not playing downloaded soundNSNotification 不播放下载的声音
【发布时间】:2016-05-03 09:37:48
【问题描述】:

我正在尝试将本地通知声音设置为我下载的音频。 但是当通知触发时没有声音播放。我不知道我哪里出错了。请看一下代码,让我知道我的错误。

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)
    }
}

【问题讨论】:

  • 确保设备不是静音或免打扰模式。
  • 我的设备未处于静音模式。它与我预先添加到我的应用程序中的声音效果很好。

标签: ios swift notifications alert uilocalnotification


【解决方案1】:

确保声音实际上在您的应用程序包中,格式正确(线性 PCM 或 IMA4 — 几乎任何解释如何为 iOS 转换声音的地方都会告诉您如何操作),并且时间不超过 30 秒.

参考链接:

Choose custom sound for local notifications

根据您的评论更新:

下载的文件不会在您的捆绑包中。所以它不会播放那种声音!!!!

【讨论】:

  • 我在通知中播放一个 mp3 文件,它工作正常。但是当我尝试设置下载的一个时,不会播放任何声音。我检查了苹果通知声音属性,我发现“public var soundName:String?//要播放的应用程序包中的资源名称或 UILocalNotificationDefaultSoundName”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-20
  • 2011-02-25
  • 2020-02-15
  • 2015-12-22
  • 2022-01-25
  • 1970-01-01
相关资源
最近更新 更多