ios - 如何在 iOS App Bundle 中创建非本地化资源

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

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

您可以将音频数据打包为 aiff、wav 或 caf 文件。然后,在 Xcode 中,将声音文件作为应用程序包的非本地化资源添加到您的项目中

我的问题是如何创建非本地化资源?当您将音频文件拖放到 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
}

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

最佳答案

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

关于ios - 如何在 iOS App Bundle 中创建非本地化资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33897697/

相关文章:

actionscript-3 - Flash AS3:动态声音采样率不是44100hz?

iphone - 第四代音频服务音量问题。 iPod触摸

ios - laravel - 在登录移动应用程序时保存 session 凭据

objective-c - 越狱的 iOS 从后台应用程序截图

ios - 识别并关闭非事件线程

ios - 在 UIWebView 中不断丢失 php session cookie

c# - Unity AudioSource 无法播放剪辑

ios - 如果站点具有用于确定区域设置的子路径,如何将路径添加到 apple-app-site-association 文件?

iOS:无法完成套接字错误操作 Broken pipe

xcode - 计算 Xcode 项目中的总行数