Question

There is a library in my project that is adding audio property listeners. I really need to be able to block it from doing so, but I don't have the source code.

I've done a swizzle before for the addObserver method in NSNotificationCenter. Could you help me do the same for AudioSessionAddPropertyListener? If the method trying to be added in the call does not match my whitelist, I want to block it. Otherwise, I'll call the original method.

I don't know what class for which I should overload the load function. I'm looking inside of Audio.h. I'm adding some pseudo/real/badlyNamed code so you can see what I'm trying to do.

#import <AudioToolbox/AudioToolbox.h>
@interface AuidoClassUmm (SOMETHING)
@end

+ (void) load
{
    Method original, swizzled;
    original = class_getInstanceMethod(self, @selector(AudioSessionAddPropertyListener:selector:name:object:));
    swizzled = class_getInstanceMethod(self, @selector(swizzled_AudioSessionAddPropertyListener:selector:name:object:));

    method_exchangeImplementations(original, swizzled);
}

-(void) swizzled_AudioSessionAddPropertyListener:selector:name:object:
{
    if(//funciton object I don't like)
    {
        return;
    }
    else
    {
        // Calls the original addObserver function
        [self swizzled_AudioSessionAddPropertyListener::notificationObserver selector:notificationSelector name:notificationName object:notificationSender];
    }
}
Was it helpful?

Solution

AudioSessionAddPropertyListener() is a C function, not an Objective-C method. You can't swizzle it.

(Even if you could swizzle it, that would almost certainly be a bad idea.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top