Camera permission fixup

- remove unknown segue, otherwise couldn't compile project
- translated english strings
- added translation comments
- reused existing "dismiss" string
- deselected row after dismissing permissions alert in linked devices
  screen

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent c152c1c83a
commit b8fc4001ec

@ -1519,7 +1519,6 @@
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
<segue reference="xo7-5J-BJb"/>
<segue reference="tfr-ZV-qWs"/>
<segue reference="E8S-Yc-X7E"/>
</inferredMetricsTieBreakers>

@ -10,7 +10,8 @@
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (CameraPermissions)
-(void)ows_askForCameraPermissions:(void(^)())permissionsGrantedCallback;
- (void)ows_askForCameraPermissions:(void (^)())permissionsGrantedCallback
alertActionHandler:(nullable void (^)())alertActionHandler;
@end
NS_ASSUME_NONNULL_END

@ -13,7 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
@implementation UIViewController (CameraPermissions)
-(void)ows_askForCameraPermissions:(void(^)())permissionsGrantedCallback
- (void)ows_askForCameraPermissions:(void (^)())permissionsGrantedCallback
alertActionHandler:(nullable void (^)())alertActionHandler
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
DDLogError(@"Camera ImagePicker source not available");
@ -21,13 +22,25 @@ NS_ASSUME_NONNULL_BEGIN
}
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusDenied) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CAMERA_PERMISSION_TITLE",nil) message:NSLocalizedString(@"CAMERA_PERMISSION_MESSAGE",nil) preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CAMERA_PERMISSION_PROCEED",nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"MISSING_CAMERA_PERMISSION_TITLE", @"Alert title")
message:NSLocalizedString(@"MISSING_CAMERA_PERMISSION_MESSAGE", @"Alert body")
preferredStyle:UIAlertControllerStyleAlert];
NSString *settingsTitle = NSLocalizedString(@"OPEN_SETTINGS_BUTTON", @"Button text which opens the settings app");
UIAlertAction *openSettingsAction = [UIAlertAction actionWithTitle:settingsTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}]];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CAMERA_PERMISSION_CANCEL",nil) style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:[UIUtil modalCompletionBlock]];
if (alertActionHandler) {
alertActionHandler();
}
}];
[alert addAction:openSettingsAction];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"DISMISS_BUTTON_TEXT", nil)
style:UIAlertActionStyleCancel
handler:alertActionHandler];
[alert addAction:dismissAction];
[self presentViewController:alert animated:YES completion:nil];
} else if (status == AVAuthorizationStatusAuthorized) {
permissionsGrantedCallback();
} else if (status == AVAuthorizationStatusNotDetermined) {

@ -153,7 +153,8 @@ NS_ASSUME_NONNULL_BEGIN
completion:nil];
[self.qrScanningController startCapture];
}];
}
alertActionHandler:nil];
}
// pragma mark - OWSQRScannerDelegate

@ -1569,8 +1569,8 @@ typedef enum : NSUInteger {
picker.allowsEditing = NO;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]];
}];
}
alertActionHandler:nil];
}
- (void)chooseFromLibrary {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

@ -255,9 +255,15 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
{
[self ows_askForCameraPermissions:^{
[self performSegueWithIdentifier:@"LinkDeviceSegue" sender:self];
}];
}
alertActionHandler:^{
// HACK to unselect rows when swiping back
// http://stackoverflow.com/questions/19379510/uitableviewcell-doesnt-get-deselected-when-swiping-back-quickly
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == OWSLinkedDevicesTableViewControllerSectionAddDevice) {

Loading…
Cancel
Save