【问题标题】:How to create a nonlocalized resource within an iOS App Bundle如何在 iOS App Bundle 中创建非本地化资源
【发布时间】:2016-02-27 03:11:03
【问题描述】:

我正在尝试在我的应用程序收到通知时播放自定义声音,作为Apple Docs 的一部分,这应该通过以下方式完成:

You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle

我的问题是如何创建非本地化资源?当您将音频文件拖放到 Xcode 项目中时,它会自动创建吗?它是否在 Info.plist 中指定?

我可以使用以下代码播放声音文件:

if let buttonBeep = self.setupAudioPlayerWithFile("0897", type:"aiff") {
    self.buttonBeep = buttonBeep
}

buttonBeep?.volume = 1.0
buttonBeep?.play()

...

func setupAudioPlayerWithFile(file:NSString, type:NSString) -> AVAudioPlayer?  {
    let path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String)
    let url = NSURL.fileURLWithPath(path!)
    var audioPlayer:AVAudioPlayer?
    do {
        try audioPlayer = AVAudioPlayer(contentsOfURL: url)
    } catch {
        print("Player not available")
    }

    return audioPlayer
}

但收到推送通知时没有声音播放。

【问题讨论】:

    标签: ios xcode audio push-notification apple-push-notifications


    【解决方案1】:

    当您将声音文件拖入 Xcode 时,请确保选中“添加到目标”复选框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 2019-04-18
      • 1970-01-01
      • 2011-08-18
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      相关资源
      最近更新 更多