From e14cc3c0faa62c6718316a6808d6ab9a466da672 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Mon, 25 Oct 2021 16:36:37 -0700 Subject: [PATCH] compose: Link to Settings on iOS for permissions, when not granted at first An instance of #3814. --- src/compose/ComposeMenu.js | 30 ++++++++++++++++++++++++++-- static/translations/messages_en.json | 4 ++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/compose/ComposeMenu.js b/src/compose/ComposeMenu.js index 03ae2b74bf1..5f425be3a78 100644 --- a/src/compose/ComposeMenu.js +++ b/src/compose/ComposeMenu.js @@ -1,7 +1,7 @@ /* @flow strict-local */ import React, { PureComponent } from 'react'; import type { ComponentType } from 'react'; -import { Platform, View } from 'react-native'; +import { Platform, View, Alert, Linking } from 'react-native'; import type { DocumentPickerResponse } from 'react-native-document-picker'; import { launchCamera, launchImageLibrary } from 'react-native-image-picker'; @@ -98,7 +98,33 @@ class ComposeMenuInner extends PureComponent { const errorCode = response.errorCode; if (errorCode != null) { - showErrorAlert(_('Error'), response.errorMessage); + if (Platform.OS === 'ios' && errorCode === 'permission') { + // iOS has a quirk where it will only request the native + // permission-request alert once, the first time the app wants to + // use a protected resource. After that, the only way the user can + // grant it is in Settings. + Alert.alert( + _('Permissions needed'), + _('To upload an image, please grant Zulip additional permissions in Settings.'), + [ + { text: _('Cancel'), style: 'cancel' }, + { + text: _('Open settings'), + onPress: () => { + Linking.openSettings(); + }, + style: 'default', + }, + ], + ); + } else { + const { errorMessage } = response; + showErrorAlert(_('Error'), errorMessage); + logging.error(_('Unexpected error from image picker'), { + errorCode, + errorMessage: errorMessage ?? '[nullish]', + }); + } return; } diff --git a/static/translations/messages_en.json b/static/translations/messages_en.json index 080568625e0..1d4dbee0237 100644 --- a/static/translations/messages_en.json +++ b/static/translations/messages_en.json @@ -1,4 +1,8 @@ { + "To upload an image, please grant Zulip additional permissions in Settings.": "To upload an image, please grant Zulip additional permissions in Settings.", + "Permissions needed": "Permissions needed", + "Open settings": "Open settings", + "Unexpected error from image picker": "Unexpected error from image picker", "Error": "Error", "Something went wrong, and your message was not sent.": "Something went wrong, and your message was not sent.", "Message not sent": "Message not sent",