AVAudioSessionInterruptionNotification not fired when Video/Camera is used

后端 未结 1 555
深忆病人
深忆病人 2021-01-25 11:44

I have some SIP application. Until I\'ve used audio only evrything was working correctly, I was receiving AVAudioSessionInterruptionNotification when it was necessa

相关标签:
1条回答
  • 2021-01-25 12:29

    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
    
    0 讨论(0)
提交回复
热议问题