Cordova 2.8.1:在ios上使用photolibarary源的camera.getPicture

使用cordova 2.8.1我试图用photolibrary做一个camera.getPicture。 它似乎适用于Android但不适用于iOS。 下面是我如何调用getPicture代码。 在带有iOS 6的iPhone 4s上,它允许我选择一个图像,但是一旦完成,就会调用错误回调,参数为null

var options = { quality : 30, destinationType : Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.PHOTOLIBRARY, correctOrientation: true, targetWidth: 800, targetHeight: 800 }; navigator.camera.getPicture(this.captureSuccessPre, this.captureError, options); 

有人告诉我在console.logs周围添加一个超时。 在phonegaps文档中,它声明围绕警报这样做。 下面是我的错误回调。 记录[错误空]

 captureError: function(error){ setTimeout(function(){ console.log("error " + error); //logs error null }, 100); } 

有人有主意吗。 我一直在苦苦挣扎几天。 如果它有助于任何这个代码完美的

 sourceType : Camera.PictureSourceType.CAMERA, 

我也有完全一样的问题; 似乎与DestinationType.FILE_URI有关。

尝试这个:

 var options = { quality : 30, destinationType: navigator.camera.DestinationType.NATIVE_URI, sourceType : Camera.PictureSourceType.PHOTOLIBRARY, correctOrientation: true, targetWidth: 800, targetHeight: 800 }; 

看起来2.8.0中有一个错误 – 如果你升级到2.9.0它修复了它([CB-3757]来自photolib的camera.getPicture在iOS上失败 – https://github.com/phonegap/phonegap/blob/ 2.9.0 / changelog )

试试这个它会帮助你

 function uploadFromGallery(){ navigator.camera.getPicture(uploadPhoto,function(message){ console.log('get picture failed'); }, {quality: 75, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY, allowEdit:true, targetWidth: 100, targetHeight: 100 }); }