Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt error on iOS when camera access is disallowed #1036

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* The react native image/document pickers work for iOS/Android, but we want to wrap them both within AttachmentPicker
*/
import {Alert, Linking} from 'react-native';
import RNImagePicker from 'react-native-image-picker';
import RNDocumentPicker from 'react-native-document-picker';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -51,6 +52,24 @@ function showDocumentPicker(callback) {
function show(callback) {
RNImagePicker.showImagePicker(imagePickerOptions, (response) => {
if (response.error) {
if (response.error === 'Camera permissions not granted') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional context on the unconventional error check here:

Since we're using the deprecated 2.x.x react-native-image-picker module at the moment, we're forced to use the textual error message returned by the library.

The new 3.x.x version has a dedicated error code for permissions, which is a far cleaner solution.

@AndrewGable Are there any plans for us to upgrade react-native-image-picker, or should this solution be acceptable for now? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think updating to the latest would be great 👍

Alert.alert(
// eslint-disable-next-line max-len
'ExpensifyCash does not have access to your camera. To enable access, tap Settings and turn on Camera.',
robertjchen marked this conversation as resolved.
Show resolved Hide resolved
'',
[
{
text: 'Cancel',
style: 'cancel',
},
{
text: 'Settings',
onPress: () => Linking.openURL('app-settings:'),
},
],
{cancelable: false},
);
}
console.debug(`Error during attachment selection: ${response.error}`);
} else if (response.customButton) {
showDocumentPicker(callback);
Expand Down