简体   繁体   English

Ionic 2应用程式当机

[英]Ionic 2 app crash

I am selecting images through Cordova image picker plugin and converting them to base64 string. 我通过Cordova图像选择器插件选择图像并将其转换为base64字符串。 After that, I clear the temp images on android which was generated by plugin. 之后,我清除了由插件生成的android上的临时图像 Everything works fine; 一切正常; all temporary images get removed but after that the application crashes(not crashes natively, just go to background and reintialize when resumed again) sometimes . 所有的临时映像都会被删除,但是之后应用程序崩溃(不是本地崩溃,只是进入后台并在再次恢复时重新初始化)有时 Even when there is no processing or any function call after that. 即使之后没有任何处理或任何函数调用。 Is there any way I could trace why it is happening because no line of code is there to execute after cleaning those temp files. 我有什么办法可以跟踪为什么会发生这种情况,因为在清理这些临时文件后没有代码行可以执行。

According to the Documentation in https://github.com/Telerik-Verified-Plugins/ImagePicker 根据https://github.com/Telerik-Verified-Plugins/ImagePicker中的文档

If Base64 Strings are being returned, there is nothing to clean up. 如果返回Base64字符串,则没有任何清理内容。

May be you don't have to clean up at all. 也许您根本不需要清理。

Add camera plugin to your app ionic plugin add cordova-plugin-camera Then in ts file use the following code 将相机插件添加到您的应用程序ionic plugin add cordova-plugin-camera然后在ts文件中使用以下代码

  takePicture() {
    var options = {
      sourceType: Camera.PictureSourceType.CAMERA,
      destinationType: Camera.DestinationType.DATA_URL
    };
    Camera.getPicture(options).then((imageData) => {
      this.base64Image = 'data:image/jpeg;base64,' + imageData;
      this.photoTaken = true;
      this.photoSelected = false;
    }, (err) => {
      // Handle error
    });
  }

In html use this 在html中使用此

<ion-col>
  <button ion-button (click)="takePicture()">Edit</button>
</ion-col>
  <ion-col>
    <img [src]="base64Image" *ngIf="base64Image" />
  </ion-col>

this will directly give base64 image 这将直接给出base64图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM