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

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent 5e61307ce3
commit 5cc292fb6c

@ -4,8 +4,8 @@
#import "AttachmentSharing.h"
#import "TSAttachmentStream.h"
#import "Threading.h"
#import "UIUtil.h"
#import <SignalServiceKit/Threading.h>
@implementation AttachmentSharing

@ -2473,7 +2473,10 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
- (void)takePictureOrVideo
{
[self ows_askForCameraPermissions:^{
[self ows_askForCameraPermissions:^(BOOL granted) {
if (!granted) {
return;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = @[ (__bridge NSString *)kUTTypeImage, (__bridge NSString *)kUTTypeMovie ];
@ -3060,33 +3063,13 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
return;
}
<<<<<<< HEAD
if (granted) {
[strongSelf startRecordingVoiceMemo];
} else {
DDLogInfo(@"%@ we do not have recording permission.", self.logTag);
[strongSelf cancelVoiceMemo];
[OWSAlerts showNoMicrophonePermissionAlert];
}
});
||||||| merged common ancestors
if (granted) {
[strongSelf startRecordingVoiceMemo];
} else {
DDLogInfo(@"%@ we do not have recording permission.", self.tag);
[strongSelf cancelVoiceMemo];
[OWSAlerts showNoMicrophonePermissionAlert];
}
});
=======
if (granted) {
[strongSelf startRecordingVoiceMemo];
} else {
DDLogInfo(@"%@ we do not have recording permission.", self.tag);
DDLogInfo(@"%@ we do not have recording permission.", self.logTag);
[strongSelf cancelVoiceMemo];
[OWSAlerts showNoMicrophonePermissionAlert];
}
>>>>>>> Don't ask for microphone permissions if app is not active.
}];
}

@ -118,19 +118,19 @@ NS_ASSUME_NONNULL_BEGIN
{
[super viewDidAppear:animated];
[self ows_askForCameraPermissions:^{
[self ows_askForCameraPermissions:^(BOOL granted) {
if (granted) {
// Camera stops capturing when "sharing" while in capture mode.
// Also, it's less obvious whats being "shared" at this point,
// so just disable sharing when in capture mode.
// Camera stops capturing when "sharing" while in capture mode.
// Also, it's less obvious whats being "shared" at this point,
// so just disable sharing when in capture mode.
DDLogInfo(@"%@ Showing Scanner", self.logTag);
DDLogInfo(@"%@ Showing Scanner", self.logTag);
[self.qrScanningController startCapture];
}
failureCallback:^{
[self.qrScanningController startCapture];
} else {
[self.navigationController popViewControllerAnimated:YES];
}];
}
}];
}
#pragma mark - OWSQRScannerDelegate

@ -256,7 +256,10 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
if (indexPath.section == OWSLinkedDevicesTableViewControllerSectionAddDevice)
{
[self ows_askForCameraPermissions:^{
[self ows_askForCameraPermissions:^(BOOL granted) {
if (!granted) {
return;
}
[self performSegueWithIdentifier:@"LinkDeviceSegue" sender:self];
}];
}

@ -1108,16 +1108,15 @@ protocol CallServiceObserver: class {
return
}
frontmostViewController.ows_ask(forCameraPermissions: { [weak self] in
// Success callback; camera permissions are granted.
frontmostViewController.ows_ask(forCameraPermissions: { [weak self] granted in
guard let strongSelf = self else {
return
}
strongSelf.setHasLocalVideoWithCameraPermissions(hasLocalVideo: hasLocalVideo)
}, failureCallback: {
if (granted) {
// Success callback; camera permissions are granted.
strongSelf.setHasLocalVideoWithCameraPermissions(hasLocalVideo: hasLocalVideo)
} else {
// Failed callback; camera permissions are _NOT_ granted.
// We don't need to worry about the user granting or remoting this permission
@ -1125,6 +1124,7 @@ protocol CallServiceObserver: class {
// permission kills the app.
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"))
}
})
}

@ -8,8 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (Permissions)
- (void)ows_askForCameraPermissions:(void (^)())successCallback;
- (void)ows_askForCameraPermissions:(void (^)())successCallback failureCallback:(nullable void (^)())failureCallback;
- (void)ows_askForCameraPermissions:(void (^)(BOOL granted))callback;
- (void)ows_askForMicrophonePermissions:(void (^)(BOOL granted))callback;

@ -6,35 +6,32 @@
#import "UIUtil.h"
#import "UIViewController+Permissions.h"
#import <AVFoundation/AVFoundation.h>
#import <SignalServiceKit/Threading.h>
NS_ASSUME_NONNULL_BEGIN
@implementation UIViewController (Permissions)
- (void)ows_askForCameraPermissions:(void (^)(void))successCallback
{
[self ows_askForCameraPermissions:successCallback failureCallback:nil];
}
- (void)ows_askForCameraPermissions:(void (^)(void))successCallback failureCallback:(nullable void (^)(void))failureCallback
- (void)ows_askForCameraPermissions:(void (^)(BOOL granted))callbackParam
{
DDLogVerbose(@"[%@] ows_askForCameraPermissions", NSStringFromClass(self.class));
// Avoid nil tests below.
if (!failureCallback) {
failureCallback = ^{
};
}
// Ensure callback is invoked on main thread.
void (^callback)(BOOL) = ^(BOOL granted) {
DispatchMainThreadSafe(^{
callbackParam(granted);
});
};
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
DDLogError(@"Skipping camera permissions request when app is not active.");
failureCallback();
callback(NO);
return;
}
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
DDLogError(@"Camera ImagePicker source not available");
failureCallback();
callback(NO);
return;
}
@ -52,34 +49,28 @@ NS_ASSUME_NONNULL_BEGIN
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
[[UIApplication sharedApplication] openSystemSettings];
failureCallback();
callback(NO);
}];
[alert addAction:openSettingsAction];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:CommonStrings.dismissButton
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
failureCallback();
callback(NO);
}];
[alert addAction:dismissAction];
[self presentViewController:alert animated:YES completion:nil];
} else if (status == AVAuthorizationStatusAuthorized) {
successCallback();
callback(YES);
} else if (status == AVAuthorizationStatusNotDetermined) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
completionHandler:^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
successCallback();
} else {
failureCallback();
}
});
callback(granted);
}];
} else {
DDLogError(@"Unknown AVAuthorizationStatus: %ld", (long)status);
failureCallback();
callback(NO);
}
}
@ -89,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN
// Ensure callback is invoked on main thread.
void (^callback)(BOOL) = ^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{
DispatchMainThreadSafe(^{
callbackParam(granted);
});
};

Loading…
Cancel
Save