ionic-framework - Ionic 照片库无法在 iOS 设备中加载
问题描述
我们需要从相机或图书馆(照片库)加载照片并上传。在 Android 设备上工作正常,但 iOS 出现以下错误:TypeError: Object( WEBPACK_IMPORTED_MODULE_1__ionic_native_core ["cordova"]) is not a function。(在 'Object( WEBPACK_IMPORTED_MODULE_1__ionic_native_core ["cordova"])(this, "getPicture", { "callbackOrder": "reverse" }, arguments)', 'Object( WEBPACK_IMPORTED_MODULE_1__ionic_native_core ["cordova"])' 是 Object 的一个实例)
此外,有关更多详细信息,请参阅随附的屏幕截图。
在此处输入图像描述 代码:if(sourceType=='library') {
const Liboptions: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType:0,
saveToPhotoAlbum:true,
targetWidth:1024,
targetHeight:720,
allowEdit:true
}
this.camera.getPicture(Liboptions).then((imagePath) => {
// Special handling for Android library
var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}, (err) => {
this.presentToast('Error while selecting image.');
});
} else {
const CamOptions: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.CAMERA,
targetWidth:1024,
targetHeight:720
}
//options.popoverOptions = CameraPopoverOption; options.correctOrientation = true;
this.camera.getPicture(CamOptions).then((imagePath) => {
// Special handling for Android library
var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}, (err) => {
this.presentToast('Error while selecting image.');
});
}
解决方案
您需要在 ios 平台的配置文件中添加此行
<config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
<string>You can take photos</string>
</config-file>
推荐阅读
- arrays - perl 中是否有一个函数来检查 2 个数组是否包含相同的内容(尽管不一定是相同的顺序)?
- c - 从 C 中的 GtkMenuItem 捕获关键事件
- c# - 我将如何编写正则表达式来匹配数字或字母数字单词,而不是没有数字的单词?
- python - 如何根据箱的共同条件来识别分箱事件?(scipy.binned_statistic)
- python - VS Code 自动激活虚拟环境
- python-3.x - ImportError:导入 gensim 时无法导入名称“已弃用”
- react-native - 当我在 react native 0.61+ 中添加本机库时,我应该生成本机构建吗?
- java - 将 pom 中表示的 EL 函数版本转换为属性标签中维护的 ACTUAL 值
- macos - 多个 USB 设备在 Mac OS 上显示为一个
- c# - Winforms中的消息框内的下拉/选择