本机相机离子使应用程序崩溃后拍照

时间:2018-03-10 11:45:52

标签: ionic-framework ionic2 ionic3

我已经尝试了一些解决方案,但我的应用程序保持原状(我在ios设备上测试)

我的代码

getPictureFromCamera() {
    return this.getImage(this.camera.PictureSourceType.CAMERA);
  }

  getPictureFromPhotoLibrary() {
    return this.getImage(this.camera.PictureSourceType.PHOTOLIBRARY);
  }

  getImage(pictureSourceType, quality = 100, allowEdit = true, saveToAlbum = true) {
    const options = {
      quality,
      allowEdit,
      targetWidth: 100,
      targetHeight: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      mediaType: this.camera.MediaType.PICTURE,
      sourceType: pictureSourceType,
      encodingType: this.camera.EncodingType.JPEG,
      saveToPhotoAlbum: saveToAlbum
    };


    return this.camera.getPicture(options).then(imageData => {
      const base64Image = 'data:image/jpeg;base64,' + imageData;
      return base64Image;
    }, error => {
      console.log('CAMERA ERROR -> ' + JSON.stringify(error));
    });
  }
}

我还添加了targetWidth和targetHeight 我使用cordova_plugin版本4.0.2

  <plugin name="cordova-plugin-camera" spec="^4.0.2"/>

我还在config.xml

中将edit-config添加到ios版本中
  <platform name="ios">
    <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>
  </platform>

但我拍照后我的应用程序仍然崩溃

0 个答案:

没有答案