Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Permissions.request('camera').then(res => {
switch (res) {
case "authorized":
/** 调用系统拍照功能 */
ImagePicker.launchCamera({}, response => {
if (response.didCancel) {
// window.console.log('User cancelled image picker');
}
else if (response.error) {
// window.console.log('ImagePicker Error: ', res.error);
}
else if (response.customButton) {
// window.console.log('User tapped custom button: ', response.customButton);
}
else {
this.setState({
headPicture: response.uri
})
}
})
break;
openCamera() {
// Launch Camera:
ImagePicker.launchCamera(options, (response) => {
// Same code as in above section!
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
// let source = { uri: 'data:image/jpeg;base64,' + response.data }
// console.log('source = ', source)
this.props.route.params.response(response)
Permissions.request('camera').then(res => {
switch (res) {
case "authorized":
/** 调用系统拍照功能 */
ImagePicker.launchCamera({}, response => {
if (response.didCancel) {
// window.console.log('User cancelled image picker');
}
else if (response.error) {
// window.console.log('ImagePicker Error: ', res.error);
}
else if (response.customButton) {
// window.console.log('User tapped custom button: ', response.customButton);
}
else {
if (ImageData.selectImgList.length < 4) {
ImageData.selectImgList.push({
uri: response.uri,
isSelect: true,
filename: response.uri.slice(response.uri.lastIndexOf('/') + 1)
})
handleCameraPicker() {
this.setState({
isEmoji: false
})
// Launch Camera:
ImagePicker.launchCamera(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
}
else if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
}
else {
// You can display the image using either data...
//const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};
// or a reference to the platform specific asset location
() => {
//启动相机拍照
ImagePicker.launchCamera(AppConfig.IMAGE_PICKER_OPTIONS, (response) => {
console.log({response});
this.dismissOverlay();
if (!response.error && response.uri && this.props.callback) {
this.props.callback({
uri: response.uri,
path: response.path,
fileSize: response.fileSize,
fileName: response.fileName,
width: response.width,
height: response.height,
});
} else {
ToastAI.showShortBottom("不能打开照相机!");
}
});
}, () => {
handleCameraCapture = () => {
const options = {
storageOptions: {
cameraRoll: true,
waitUntilSaved: true,
},
};
ImagePicker.launchCamera(options, this.handleImagePickerResponse);
};
},
permissionDenied: {
title,
text,
reTryTitle: formatMessage({
id: 'mobile.permission_denied_retry',
defaultMessage: 'Settings',
}),
okTitle: formatMessage({id: 'mobile.permission_denied_dismiss', defaultMessage: 'Don\'t Allow'}),
},
};
const hasCameraPermission = await this.hasPhotoPermission(source, mediaType);
if (hasCameraPermission) {
ImagePicker.launchCamera(options, (response) => {
if (response.error || response.didCancel) {
return;
}
this.uploadFiles([response]);
});
}
};
if (response.didCancel || !this.props.conversationIDKey) {
return
}
if (response.error) {
this.props.onFilePickerError(new Error(response.error))
return
}
const filename = isIOS ? response.uri.replace('file://', '') : response.path
if (filename) {
this.props.onAttach([filename])
}
}
switch (location) {
case 'camera':
launchCamera({mediaType, permissionDenied, takePhotoButtonTitle, title}, handleSelection)
break
case 'library':
launchImageLibrary({mediaType, permissionDenied, takePhotoButtonTitle, title}, handleSelection)
break
}
}
},
permissionDenied: {
title,
text,
reTryTitle: formatMessage({
id: 'mobile.permission_denied_retry',
defaultMessage: 'Settings',
}),
okTitle: formatMessage({id: 'mobile.permission_denied_dismiss', defaultMessage: 'Don\'t Allow'}),
},
};
const hasCameraPermission = await this.hasPhotoPermission(source, mediaType);
if (hasCameraPermission) {
ImagePicker.launchCamera(options, (response) => {
if (response.error || response.didCancel) {
return;
}
this.uploadFiles([response]);
});
}
};
new Promise((resolve, reject: (reason: Error) => void) => {
ImagePicker.launchCamera(
{},
({ didCancel, error, uri }: ImagePickerResponse) => {
if (didCancel) {
reject(new Error('cancelled'))
} else if (error) {
reject(new Error(error))
} else {
resolve(uri)
}
}
)
})
)