嘿,我对x-code编程非常陌生,我一直在关注geeky lemon的教程,我想在我的项目中添加声音。我正在尝试创建一个简单的钢琴应用程序。我已经正确地执行了每一步,我的代码与他们的代码完全相同,但是当我运行程序时,iphone模拟器在黑屏上冻结并打开xcode
线程1:信号SIGABRT
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}T}
在控制台中,错误是: 由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' * - [NSURL initFileURLWithPath:]:nil字符串参数' * 首先抛出调用堆栈:
我的代码是: .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
我已经对此做了一些研究,一个答案是捆绑不正确或类似的东西,但我检查了我的构建阶段,我的所有资源都在那里,没有一个是红色的。