Don't ask for camera permissions if app is not active.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent f757b7dcb1
commit f86882b5ff

@ -39,6 +39,7 @@
#import "UIImage+OWS.h"
#import "UIUtil.h"
#import "UIView+OWS.h"
#import "UIViewController+CameraPermissions.h"
#import "ViewControllerUtils.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <Foundation/Foundation.h>

@ -1103,33 +1103,34 @@ protocol CallServiceObserver: class {
func setHasLocalVideo(hasLocalVideo: Bool) {
AssertIsOnMainThread()
let authStatus = AVCaptureDevice.authorizationStatus(forMediaType:AVMediaTypeVideo)
switch authStatus {
case .notDetermined:
Logger.debug("\(TAG) authStatus: AVAuthorizationStatusNotDetermined")
break
case .restricted:
Logger.debug("\(TAG) authStatus: AVAuthorizationStatusRestricted")
break
case .denied:
Logger.debug("\(TAG) authStatus: AVAuthorizationStatusDenied")
break
case .authorized:
Logger.debug("\(TAG) authStatus: AVAuthorizationStatusAuthorized")
break
guard let frontmostViewController = UIApplication.shared.frontmostViewController else {
owsFail("\(TAG) could not identify frontmostViewController in \(#function)")
return
}
frontmostViewController.ows_ask(forCameraPermissions: { [weak self] in
// Success callback; camera permissions are granted.
guard let strongSelf = self else {
return
}
strongSelf.setHasLocalVideoWithCameraPermissions(hasLocalVideo: hasLocalVideo)
}, failureCallback: {
// Failed callback; camera permissions are _NOT_ granted.
// We don't need to worry about the user granting or remoting this permission
// during a call while the app is in the background, because changing this
// permission kills the app.
if authStatus != .authorized {
OWSAlerts.showAlert(withTitle: NSLocalizedString("MISSING_CAMERA_PERMISSION_TITLE", comment: "Alert title when camera is not authorized"),
message: NSLocalizedString("MISSING_CAMERA_PERMISSION_MESSAGE", comment: "Alert body when camera is not authorized"))
return
})
}
private func setHasLocalVideoWithCameraPermissions(hasLocalVideo: Bool) {
AssertIsOnMainThread()
guard let call = self.call else {
// This should never happen; return to a known good state.
owsFail("\(TAG) call was unexpectedly nil in \(#function)")
@ -1434,7 +1435,7 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread()
if case CallError.assertionError(description: let description) = error {
owsFail(description)
Logger.error(description)
}
if let failedCall = failedCall {

@ -19,12 +19,20 @@ NS_ASSUME_NONNULL_BEGIN
- (void)ows_askForCameraPermissions:(void (^)(void))permissionsGrantedCallback
failureCallback:(nullable void (^)(void))failureCallback
{
DDLogVerbose(@"%@ ows_askForCameraPermissions", NSStringFromClass(self.class));
// Avoid nil tests below.
if (!failureCallback) {
failureCallback = ^{
};
}
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
DDLogError(@"Skipping camera permissions request when app is not active.");
failureCallback();
return;
}
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
DDLogError(@"Camera ImagePicker source not available");
failureCallback();

Loading…
Cancel
Save