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.

Also log to Sentry when the error isn't one we've handled yet.
  • Loading branch information
chrisbobbe committed Oct 26, 2021
1 parent 79f2703 commit 251f83f
Show file tree
Hide file tree
Showing 2 changed files with 31 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
3 changes: 3 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"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",
"Error": "Error",
"Storage permission needed": "Storage permission needed",
"Zulip will save a copy of your photo on your device. To do so, Zulip will need permission to store files on your device.": "Zulip will save a copy of your photo on your device. To do so, Zulip will need permission to store files on your device.",
Expand Down

0 comments on commit 251f83f

Please sign in to comment.