2017-09-25 41 views
0

嗨我不能复制iPhone手机上的官方本地目录。 我在此功能copyFileToLocalDir处收到错误消息。 每当我从手机的相册和相机中获取图片时,我总是会收到错误消息。在android手机上的每张照片后,每张照片都在本地线上。我怎么才能得到它? 为什么它能在上工作iOS手机在无缝工作时Android手机?离子2图像本地目录复制不起作用

presentActionSheet(){ 
    let actionSheet = this.actionSheetCtrl.create({ 
     title : "Resim Kaynağını Seçiniz", 
     buttons : [{ 
     text : "Galeriden Seç", 
     handler :()=>{ 
this.takePicture(this.camera.PictureSourceType.PHOTOLIBRARY); 
     } 
     },{ 
     text : "Resim Çek", 
     handler :()=>{ 
      this.takePicture(this.camera.PictureSourceType.CAMERA); 
     } 
     }] 
    }); 
    actionSheet.present(); 
    } 
    takePicture(SOURCETYPE){ 
    var options = { 
     quality : 25, 
     sourceType : SOURCETYPE, 
     destinationType : this.camera.DestinationType.FILE_URI, 
     encodingType : this.camera.EncodingType.JPEG, 
     saveToPhotoAlbum : false, 
     correctOrientation : true 
    }; 
    var yerelDizinAndroid; 
    var yerelDizinIOS; 
    this.camera.getPicture(options).then((imagePath)=>{ 
     if(this.platform.is('android') && SOURCETYPE === this.camera.PictureSourceType.PHOTOLIBRARY){ 
     this.filePath.resolveNativePath(imagePath).then(filePath =>{ 
      let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1); 
      let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?')); 
      yerelDizinAndroid = currentName; 
      this.copyFileToLocalDir(correctPath, currentName, this.createFileName()); 
     }); 
     }else { 
     var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1); 
     var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1); 
     yerelDizinIOS = currentName; 
     this.copyFileToLocalDir(correctPath, currentName, this.createFileName()); 
    } 
    }, (err) => { 
    this.presentToast('Herhangi bir işlem yapılmadı.'); 
    /* this.file.removeDir(cordova.file.dataDirectory, yerelDizinAndroid); 
    this.file.removeDir(cordova.file.dataDirectory, yerelDizinIOS); */ 
    }); 
} 
    private createFileName() { 
    var newFileName = "S" + window.localStorage.getItem("auth_key") + ".jpg"; 
    return newFileName; 
    } 
    private copyFileToLocalDir(namePath, currentName, newFileName) { 
    this.file.copyFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(success => { 
     this.lastImage = newFileName; 
    }, (error) => { 
     this.presentToast('Görsel yerel dizine taşınamadı..'); 
    }); 
    } 
+0

什么是你所得到的特定的错误?而要清楚的是,它适用于Android,但不适用于iOS? – lintmouse

+0

是的,它不适用于iOS手机@lintmouse – Degisim

+0

如果它在一个平台上运行,但不在另一个平台上,那么它可能是特定平台上的限制/访问权限。确保您使用的是正确的文件路径。我不认为这是离子框架相关的,更像是OS/Cordova相关的。 – DanteTheSmith

回答