warning: 'AVAudioSession' may not respond to '-setActive:fooError:' [closed]
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord fooError: &fooError];开发者_运维百科
//Activate the session
[audioSession setActive:YES fooError: &fooError];
The warning i receive is
warning: 'AVAudioSession' may not respond to '-setActive:fooError:'
It looks like you your class, or a class that you're using has an instance variable called error in its header file. Try this:
NSError *fooError = nil;
oneAudioC = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&fooError];
if (fooError)
NSLog(@"%@",[fooError localizedDescription]);
Edit: Changed if (error)
to if (fooError)
The warning already tells you what the problem is: The AVAudioSession
methods are called -setCategory:error:
and -setActive:error:
, not -setCategory:fooError:
and -setActive:fooError:
, respectively. You can change parameter names any way you want but not method names:
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &fooError];
//Activate the session
[audioSession setActive:YES error: &fooError];
精彩评论