Angular 爱奥尼亚-拍照后再打电话给相机?

Angular 爱奥尼亚-拍照后再打电话给相机?,angular,ionic-framework,ionic3,Angular,Ionic Framework,Ionic3,我正在开发一个应用程序,需要至少拍摄4张照片。我正在尝试在每次拍照时重新启动相机,这样他们就不必再次单击应用程序菜单上的“拍照”按钮。以下是我目前的代码: startCamera() { if(this.pictureList.length >= 4) { this.alertController.create({ title: this.singleton.TITLE_ERROR, message: this.singleton.MESSAGE_TOO

我正在开发一个应用程序,需要至少拍摄4张照片。我正在尝试在每次拍照时重新启动相机,这样他们就不必再次单击应用程序菜单上的“拍照”按钮。以下是我目前的代码:

startCamera() {
  if(this.pictureList.length >= 4) {
    this.alertController.create({
      title: this.singleton.TITLE_ERROR,
      message: this.singleton.MESSAGE_TOOMANYPHOTOS,
      buttons: [
        {
          text: 'Ok',
        }
      ]
    }).present();
    return;
  }

  let imageData = "";
  this.camera.getPicture(this.options).then((imageData) => {
    this.pictureList.push(imageData);

    let temp = [];
    for (let i of this.pictureList) i && temp.push(i);

    this.pictureList = temp;
    this.slides.refresh();
  }, (err) => {
    console.log(err);
  });
}
但是,相机不会重新启动回到相机中吗?这有什么原因不起作用吗?我想这是因为我试图调用承诺中的函数


谢谢

也许通过递归你可以做到,我给你举一个未经证实的例子,但这在逻辑上可以为你服务:

我是基于一个将其保存在Base64中的应用程序来做这个示例的,但是根据需要在列表中应用推送

pictureList: any[];

  ngOnInit(): void {
    this.pictureList = null;
    this.optionsCamera = {
      quality: 50,
      destinationType: this._camera.DestinationType.DATA_URL,
      encodingType: this._camera.EncodingType.JPEG,
      mediaType: this._camera.MediaType.PICTURE,
      saveToPhotoAlbum: true
    };
    this.optionsGallery = {
      quality: 50,
      destinationType: this._camera.DestinationType.DATA_URL,
      sourceType: this._camera.PictureSourceType.PHOTOLIBRARY
    };
  }

  startCamera(): void {
    if (this.pictureList.length <= 4) {
      console.log('Open in length: ' + this.pictureList.length);
      this.getPhoto(this.optionsCamera);
      this.startCamera();
    }
  }

  getPhoto(options): void {
    this._camera.getPicture(options).then(
      imageData => {
        let base64Image = "data:image/jpeg;base64," + imageData;
        this.pictureList.push(base64Image);
      },
      err => {
        console.log("Could not open the camera: " + err);
      }
    );
  }
图片列表:任意[];
ngOnInit():void{
this.pictureList=null;
this.options相机={
质量:50,
destinationType:this.\u camera.destinationType.DATA\u URL,
encodingType:this.\u camera.encodingType.JPEG,
mediaType:this.\u camera.mediaType.PICTURE,
saveToPhotoAlbum:正确
};
this.optionsGallery={
质量:50,
destinationType:this.\u camera.destinationType.DATA\u URL,
sourceType:this.\u camera.PictureSourceType.PHOTOLIBRARY
};
}
startCamera():void{
如果(此图片列表长度){
让base64Image=“数据:图像/jpeg;base64,”+imageData;
this.pictureList.push(base64Image);
},
错误=>{
console.log(“无法打开摄像头:+err”);
}
);
}

Hi,这个解决方案几乎是正确的,我刚刚做了一些调整,结果在刷新幻灯片之前使用递归效果很好。谢谢你帮助我解决这个问题。