diff --git a/src/barcodescanner.ios.ts b/src/barcodescanner.ios.ts index e5f2a0a..f1b7369 100644 --- a/src/barcodescanner.ios.ts +++ b/src/barcodescanner.ios.ts @@ -16,8 +16,10 @@ export class BarcodeScannerView extends BarcodeScannerBaseView { super(); this._hasSupport = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) !== null; if (this._hasSupport) { - // play nice with others - AVAudioSession.sharedInstance().setCategoryModeOptionsError(AVAudioSessionCategoryPlayback, AVAudioSessionModeDefault, AVAudioSessionCategoryOptions.MixWithOthers); + if (typeof AVAudioSession.sharedInstance().setCategoryModeOptionsError === "function") { + // if music was playing, it would stop unless we do this: + AVAudioSession.sharedInstance().setCategoryModeOptionsError(AVAudioSessionCategoryPlayback, AVAudioSessionModeDefault, AVAudioSessionCategoryOptions.MixWithOthers); + } } } @@ -90,8 +92,10 @@ export class BarcodeScanner { private _device: AVCaptureDevice; constructor() { - // play nice with others - AVAudioSession.sharedInstance().setCategoryModeOptionsError(AVAudioSessionCategoryPlayback, AVAudioSessionModeDefault, AVAudioSessionCategoryOptions.MixWithOthers); + if (typeof AVAudioSession.sharedInstance().setCategoryModeOptionsError === "function") { + // if music was playing, it would stop unless we do this: + AVAudioSession.sharedInstance().setCategoryModeOptionsError(AVAudioSessionCategoryPlayback, AVAudioSessionModeDefault, AVAudioSessionCategoryOptions.MixWithOthers); + } this._device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo); if (this._device && this._device.hasTorch && this._device.hasFlash) {