JGMethodSwizzler icon indicating copy to clipboard operation
JGMethodSwizzler copied to clipboard

EXC_BAD_ACCESS when swizzling AVAudioSession setCategory:withOptions:error:

Open josipbernat opened this issue 10 years ago • 3 comments

Hi,

I'm trying to swizzle AVAudioSession's - (BOOL)setCategory:(NSString )category withOptions: (AVAudioSessionCategoryOptions)options error:(NSError *)outError method. Problem is that each time someone try to set category I get EXC_BAD_ACCESS. I assume problem is with this NSError ** but I'm unclear how to modify implementation then. Do you have some suggestion?

This is what I try to do:

[AVAudioSession swizzleInstanceMethod:@selector(setCategory:withOptions:error:)
                      withReplacement:JGMethodReplacementProviderBlock {

                          //return a replacement block
                          return JGMethodReplacement(BOOL, AVAudioSession *, NSString *category, AVAudioSessionCategoryOptions options, NSError **error) {

                              // We want to use AVAudioSessionCategoryPlayback always.
                              BOOL orig = JGOriginalImplementation(BOOL, AVAudioSessionCategoryPlayback, options, error);

                              //return the modified value
                              return orig;
                          };
}];

josipbernat avatar Jan 28 '15 12:01 josipbernat

Yes, NSError ** is probably the culprit, where exactly is the exception thrown?

JonasGessner avatar Jan 28 '15 14:01 JonasGessner

It's just EXC_BAD_ACCESS unfortunately.

josipbernat avatar Jan 28 '15 14:01 josipbernat

+1

wells1013 avatar Aug 12 '16 06:08 wells1013