ionic-framework - 选择相机胶卷在 iOs 的 ionic/cordova 中不起作用没有任何反应
问题描述
当我使用 this.camera.PictureSourceType.PHOTOLIBRARY 调用 getPicture 函数时,什么也没有发生。但是,它在 Android 中确实有效,但在 iO 中不适用,而且 this.camera.PictureSourceType.CAMERA 在 iO 中也有效。
private cameraOptions: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
};
public async changeProfilePicture() {
const sheet = await this.actionSheet.create({
buttons: [{
text: 'Camera',
handler: () => {
this.takePicture();
},
},
{
text: 'Foto album',
handler: () => {
this.choosePicture();
},
}
, {
text: 'Annuleren',
role: 'cancel',
handler: () => {
sheet.dismiss();
},
}],
});
sheet.present();
}
private async takePicture() {
try {
const image = await this.camera.getPicture({
...this.cameraOptions,
sourceType: this.camera.PictureSourceType.CAMERA,
});
this.userService.editProfilePicture(`data:image/jpeg;base64,${image}`).subscribe(user => {
this.user = user;
});
} catch (err) {
this.handleImageError(err);
}
}
private async choosePicture() {
try {
const image = await this.camera.getPicture({
...this.cameraOptions,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
});
this.userService.editProfilePicture(`data:image/jpeg;base64,${image}`).subscribe(user => {
this.user = user;
});
} catch (err) {
this.handleImageError(err);
}
}
解决方案
iOS 需要在访问某些本机功能时配置权限。在您的情况下,您需要在应用程序的文件中设置NSPhotoLibraryUsageDescription
密钥。Info.plist
您可以在 xcode 项目中手动编辑此文件,但最好将其放在config.xml
您的 ionic 项目中:
<config-file parent="NSPhotoLibraryUsageDescription" platform="ios" target="*-Info.plist">
<string>The app needs access to your library to...</string>
</config-file>
推荐阅读
- javascript - 单击按钮时不显示 Material-ui 菜单
- vba - 使用VBA查找一列中的值,然后将相邻列中的值相加
- javascript - Javascript array of key pair objects to JSON
- javascript - Javascript XMLHttpRequest PHP 返回“未定义”
- angular - 检测 Angular 应用程序中缺失的增强导入
- c# - 如何从 Windows 窗体中的另一个类修改 PictureBox?C#
- javascript - 我已经从 javascript 将表格附加到 html 中,但现在我想通过传递它们的 id 从字体真棒图标调用 onclick 函数
- oauth-2.0 - oauth 2.0 - Resource owner password flow, can use windows login user credentials
- r - 在 Tidyverse 管道中使用汇总值进行归一化
- c# - wpf 列表框绑定 XElement 未更新