【发布时间】: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