首页 > 解决方案 > Ionic 3 相机插件在 iPhone 上因 saveToPhotoAlbum true 而崩溃

问题描述

我正在使用 Ionic 3,我正在尝试拍照并将其直接保存到图库中。

它在 Android 上运行良好,但在 iPhone 上崩溃,当我将 saveToPhotoAlbum 设置为 false 时,它​​运行良好,所以我意识到问题出在这个选项上。

我正在使用文档代码:

home.ts:

const options: CameraOptions = {
      quality: 100,
      sourceType: PictureSourceType.CAMERA,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      saveToPhotoAlbum:true,
    }
    
    this.camera.getPicture(options).then((imageData) => {
     // imageData is either a base64 encoded string or a file URI
     // If it's base64 (DATA_URL):
     this.selectedImage = 'data:image/jpeg;base64,' + imageData;
    }, (err) => {
     // Handle error
    });    

在插件的文档中,建议将这些行添加到:

配置文件

</platform>

    <edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
        <string>need camera access to take pictures</string>
    </edit-config>
    <edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
        <string>need photo library access to get pictures from there</string>
    </edit-config>
    <edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
        <string>need location access to find things nearby</string>
    </edit-config>
    <edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
        <string>need photo library access to save pictures there</string>
    </edit-config>

标签: ionic-frameworkcameraionic3ionic-native

解决方案


推荐阅读