嘿,我对 x 代码编程非常陌生,我一直在关注 geeky lemon 的教程,我想在我的项目中添加声音。我正在尝试创建一个简单的钢琴应用程序。我正确地遵循了每一步,并且我的代码与他们的代码完全相同,尽管当我运行程序时,iphone模拟器冻结在黑屏并打开 xcode
线程1:信号SIGABRT in
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}T}
在控制台中,错误是:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' * -[NSURL initFileURLWithPath:]:nil string parameter'*首先抛出调用堆栈:
我的代码是:.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface ViewController : UIViewController
{
SystemSoundID soundID;
}
- (IBAction)c1Press:(id)sender;
@end
.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
NSURL *buttonURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Resource/Audio/keys/C1" ofType:@"MP3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef) buttonURL, &soundID);
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)c1Press:(id)sender {
AudioServicesPlaySystemSound(soundID);
}
@end
我对此进行了一些研究,一个答案是捆绑包没有正确安装或类似的东西,但我检查了我的构建阶段,我所有的资源都在那里,没有一个是红色的。