简体   繁体   English

Objective-c NSInvalidArgumentException Xcode7

[英]Objective-c NSInvalidArgumentException Xcode7

Hey Guys I'm just gonna cut to the chase I was trying to play audio 大家好,我只是想尝试播放音频

- (IBAction)click1:(id)sender{
    Drill.image = [UIImage imageNamed:@"Drillx2"];
    AudioServicesPlaySystemSound(PlaySoundID);
}

- (IBAction)click2:(id)sender
{    
    Drill.image = [UIImage imageNamed:@"Drillx1"];
}

- (void)viewDidLoad {
    NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Drill" ofType:@"m4a"]];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL, &PlaySoundID);

    [super viewDidLoad];
}

And I get this error 我得到这个错误

'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 'NSInvalidArgumentException',原因:'***-[NSURL initFileURLWithPath:]:零字符串参数'

Thanks, Derek 谢谢,德里克

Note : Yes the resource for the sound is named Drill. 注意:是,声音的资源名为Drill。

In the code 在代码中

NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Drill" ofType:@"m4a"]];

It didn't find the given file in the bundle file path. 它在捆绑文件路径中找不到给定的文件。
make sure you have added file in the proper target and also build again after adding the resource to make sure it exist in the bundle 确保您已在正确的目标中添加了文件,并在添加资源以确保其在捆绑包中之后再次进行了构建

Reference : As written in the parameter Passing nil for this parameter produces an exception. 参考 :如参数中所写, Passing nil for this parameter produces an exception.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM