To select a file using react-native-document-picker on the iOS simulator, you need to follow these steps:
npm install react-native-document-picker --save
react-native link react-native-document-picker
import DocumentPicker from 'react-native-document-picker';
const selectDocument = async () => {
try {
const result = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
});
// Do something with the picked file
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker
} else {
// Error occurred while picking the file
}
}
};
<Button title="Select Document" onPress={selectDocument} />
Note: Make sure that the simulator has access to the document that you want to select. You can add a sample document to the simulator using the "Add item" option in the simulator's "File" menu.
Asked: 2021-09-13 11:00:00 +0000
Seen: 9 times
Last updated: Jul 31 '21