Skip to content

Commit

Permalink
compose: Link to Settings on iOS for permissions, when not granted at…
Browse files Browse the repository at this point in the history
… first

An instance of zulip#3814.
  • Loading branch information
chrisbobbe committed Oct 26, 2021
1 parent 29121de commit e14cc3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/compose/ComposeMenu.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -98,7 +98,33 @@ class ComposeMenuInner extends PureComponent<Props> {

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;
}

Expand Down
4 changes: 4 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit e14cc3c

Please sign in to comment.