From 846e1be85c74897a8a335c8b24b0a1a354e62b6e Mon Sep 17 00:00:00 2001 From: sdkdimon Date: Mon, 6 Mar 2017 16:42:19 -0800 Subject: [PATCH] Fix iOS8 crash in background mode. Add system version check functionality in UIDevice+RTCDevice category. Check for iOS system version when handle capture session interruption. BUG=webrtc:7201 Review-Url: https://codereview.webrtc.org/2733773003 Cr-Commit-Position: refs/heads/master@{#17079} --- AUTHORS | 1 + .../RTCAVFoundationVideoCapturerInternal.mm | 33 ++++++++++--------- .../Framework/Classes/UIDevice+RTCDevice.mm | 8 +++++ .../Headers/WebRTC/UIDevice+RTCDevice.h | 1 + 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index e014bfb376..fb8965be07 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,6 +12,7 @@ Bridger Maxwell Christophe Dumez Cody Barnes Colin Plumb +Dmitry Lizin Eric Rescorla, RTFM Inc. Frederik Riedel, Frogg GmbH Giji Gangadharan diff --git a/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoCapturerInternal.mm b/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoCapturerInternal.mm index 5c276fc254..166a609824 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoCapturerInternal.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoCapturerInternal.mm @@ -13,6 +13,7 @@ #import #if TARGET_OS_IPHONE #import +#import "WebRTC/UIDevice+RTCDevice.h" #endif #import "RTCDispatcher+Private.h" @@ -232,21 +233,23 @@ NSString *reasonString = nil; #if defined(__IPHONE_9_0) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \ __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0 - NSNumber *reason = notification.userInfo[AVCaptureSessionInterruptionReasonKey]; - if (reason) { - switch (reason.intValue) { - case AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableInBackground: - reasonString = @"VideoDeviceNotAvailableInBackground"; - break; - case AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient: - reasonString = @"AudioDeviceInUseByAnotherClient"; - break; - case AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient: - reasonString = @"VideoDeviceInUseByAnotherClient"; - break; - case AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps: - reasonString = @"VideoDeviceNotAvailableWithMultipleForegroundApps"; - break; + if ([UIDevice isIOS9OrLater]) { + NSNumber *reason = notification.userInfo[AVCaptureSessionInterruptionReasonKey]; + if (reason) { + switch (reason.intValue) { + case AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableInBackground: + reasonString = @"VideoDeviceNotAvailableInBackground"; + break; + case AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient: + reasonString = @"AudioDeviceInUseByAnotherClient"; + break; + case AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient: + reasonString = @"VideoDeviceInUseByAnotherClient"; + break; + case AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps: + reasonString = @"VideoDeviceNotAvailableWithMultipleForegroundApps"; + break; + } } } #endif diff --git a/webrtc/sdk/objc/Framework/Classes/UIDevice+RTCDevice.mm b/webrtc/sdk/objc/Framework/Classes/UIDevice+RTCDevice.mm index 523c950645..94faf53506 100644 --- a/webrtc/sdk/objc/Framework/Classes/UIDevice+RTCDevice.mm +++ b/webrtc/sdk/objc/Framework/Classes/UIDevice+RTCDevice.mm @@ -165,4 +165,12 @@ return @"Unknown"; } ++ (double)currentDeviceSystemVersion { + return [self currentDevice].systemVersion.doubleValue; +} + ++ (BOOL)isIOS9OrLater { + return [self currentDeviceSystemVersion] >= 9.0; +} + @end diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/UIDevice+RTCDevice.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/UIDevice+RTCDevice.h index d38a3cb2db..29e4801b2e 100644 --- a/webrtc/sdk/objc/Framework/Headers/WebRTC/UIDevice+RTCDevice.h +++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/UIDevice+RTCDevice.h @@ -59,5 +59,6 @@ typedef NS_ENUM(NSInteger, RTCDeviceType) { + (RTCDeviceType)deviceType; + (NSString *)stringForDeviceType:(RTCDeviceType)deviceType; ++ (BOOL)isIOS9OrLater; @end