我在 Xcode 5.1.1 中开发了我的游戏应用程序。昨天我下载了 Xcode 6.1.1。在 Xcode 6.1.1 中,当我上传任何 iOS 8.1 模拟器时,声音不起作用。然而,声音对于所有 iOS 7 模拟器来说都运行得非常好。我正在使用 AudioToolbox.framework 来处理我的 .aiff 声音。 iOS 7 和 iOS 8 应用程序之间的编码有区别吗?还是别的什么?
在我的 ViewDidLoad 中,声音代码...
NSURL *SwishURL =[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"SwishSound" ofType:@"aiff"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)SwishURL, &SwishID);
最佳答案
我在音频方面也遇到了同样的问题,但经过一些搜索,我找到了一个适用于 Xcode 6.1.1 here 的解决方案。 .
实现是这样的:
@import AudioToolBox;
@import AVFoundation;
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound_effect" ofType: @"wav"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
AVAudioPlayer *sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
[sound play];
关于iOS 8 应用程序的声音不像 iOS 7 那样工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205105/