AJ9*_*AJ9 7 audio xcode push-notification apple-push-notifications ios
我正在尝试在我的应用程序收到通知时播放自定义声音,作为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()
Run Code Online (Sandbox Code Playgroud)
...
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
}
Run Code Online (Sandbox Code Playgroud)
但是收到推送通知时没有声音播放.
| 归档时间: |
|
| 查看次数: |
337 次 |
| 最近记录: |