I have some SIP application. Until I\'ve used audio only evrything was working correctly, I was receiving AVAudioSessionInterruptionNotification
when it was necessa
I used category and method swizzling and it works like charm.
#import "AVCaptureSession+MethodSwizzling.h"
#import <objc/runtime.h>
static void MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
Method origMethod = class_getInstanceMethod(c, origSEL);
Method overrideMethod = class_getInstanceMethod(c, overrideSEL);
if(class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, overrideMethod);
}
}
@implementation AVCaptureSession (MethodSwizzling)
- (id)initMethodSwizzling {
self = [self initMethodSwizzling]; // it is not recursion it is method swizzling
self.usesApplicationAudioSession = NO;
return self;
}
+ (void)load {
if (class_getInstanceMethod(self, @selector(setUsesApplicationAudioSession:))) {
// Swizzle methods only when it is possible to change usesApplicationAudioSession property.
MethodSwizzle(self, @selector(init), @selector(initMethodSwizzling));
}
}
@end