From faa991b0852e13f1bef17590fb8da21c3fa9e527 Mon Sep 17 00:00:00 2001 From: VladimirBrejcha Date: Fri, 5 Jun 2020 20:49:18 +0300 Subject: [PATCH] screenSharing minor bugfix --- ScreenSharing/Resources/Info.plist | 2 +- .../Stories/Main/MainViewController.swift | 12 ++++-------- Shared/PermissionsHelper.swift | 18 ++++++++++++++---- Shared/UI/AlertHelper.swift | 3 +-- Swift.xcodeproj/project.pbxproj | 2 ++ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ScreenSharing/Resources/Info.plist b/ScreenSharing/Resources/Info.plist index b80ff5f..2b06f11 100644 --- a/ScreenSharing/Resources/Info.plist +++ b/ScreenSharing/Resources/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) LSRequiresIPhoneOS NSCameraUsageDescription diff --git a/ScreenSharing/Stories/Main/MainViewController.swift b/ScreenSharing/Stories/Main/MainViewController.swift index 02e48f6..254d922 100644 --- a/ScreenSharing/Stories/Main/MainViewController.swift +++ b/ScreenSharing/Stories/Main/MainViewController.swift @@ -35,10 +35,8 @@ final class MainViewController: guard let self = self else { return } do { try self.callManager.makeOutgoingCall(to: username ?? "") - DispatchQueue.main.async { - self.view.endEditing(true) - self.present(self.storyAssembler.call, animated: true) - } + self.view.endEditing(true) + self.present(self.storyAssembler.call, animated: true) } catch (let error) { Log.e(error.localizedDescription) AlertHelper.showError(message: error.localizedDescription, on: self) @@ -68,10 +66,8 @@ final class MainViewController: callManager.didReceiveIncomingCall = { [weak self] in guard let self = self else { return } - DispatchQueue.main.async { - self.view.endEditing(true) - self.present(self.storyAssembler.incomingCall, animated: true) - } + self.view.endEditing(true) + self.present(self.storyAssembler.incomingCall, animated: true) } } diff --git a/Shared/PermissionsHelper.swift b/Shared/PermissionsHelper.swift index d990188..b129c99 100644 --- a/Shared/PermissionsHelper.swift +++ b/Shared/PermissionsHelper.swift @@ -7,12 +7,13 @@ import AVFoundation final class PermissionsHelper { static func requestRecordPermissions( includingVideo video: Bool, + accessRequestCompletionQueue: DispatchQueue = .main, completion: @escaping (Error?) -> Void ) { - requestPermissions(for: .audio) { granted in + requestPermissions(for: .audio, queue: accessRequestCompletionQueue) { granted in if granted { if video { - requestPermissions(for: .video) { granted in + requestPermissions(for: .video, queue: accessRequestCompletionQueue) { granted in completion(granted ? nil : PermissionError.videoPermissionDenied) } return @@ -24,10 +25,19 @@ final class PermissionsHelper { } } - static func requestPermissions(for mediaType: AVMediaType, completion: @escaping (Bool) -> Void) { + static func requestPermissions( + for mediaType: AVMediaType, + queue: DispatchQueue = .main, + completion: @escaping (Bool) -> Void + ) { switch AVCaptureDevice.authorizationStatus(for: mediaType) { + case .notDetermined: + AVCaptureDevice.requestAccess(for: mediaType) { granted in + queue.async { + completion(granted) + } + } case .authorized: completion(true) - case .notDetermined: AVCaptureDevice.requestAccess(for: mediaType, completionHandler: completion) case .denied: completion(false) case .restricted: completion(false) @unknown default: completion(false) diff --git a/Shared/UI/AlertHelper.swift b/Shared/UI/AlertHelper.swift index b05312b..19018e4 100644 --- a/Shared/UI/AlertHelper.swift +++ b/Shared/UI/AlertHelper.swift @@ -66,11 +66,10 @@ final class AlertHelper { } static func showErrorWithSettingsAction( - title: String = "Something went wrong", message: String, on viewController: UIViewController? = nil ) { - showError(message: title, action: accessSettingsAction, on: viewController) + showError(message: message, action: accessSettingsAction, on: viewController) } static func showAlert( diff --git a/Swift.xcodeproj/project.pbxproj b/Swift.xcodeproj/project.pbxproj index 40971ee..b72b20d 100644 --- a/Swift.xcodeproj/project.pbxproj +++ b/Swift.xcodeproj/project.pbxproj @@ -1716,6 +1716,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_TEAM = W9BHJBL635; INFOPLIST_FILE = "$(SRCROOT)/ScreenSharing/Resources/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 11.0; @@ -1735,6 +1736,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_OBJC_WEAK = YES; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_TEAM = W9BHJBL635; INFOPLIST_FILE = "$(SRCROOT)/ScreenSharing/Resources/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 11.0;