我开发了适用于Android和iOS的Cordova 4.2.0应用程序。在成功签署Android应用程序并测试Galaxy Note 10.1上的所有功能后,我将www代码复制到我的MacBook并为我的iPad 4(iOS 8.3)构建它。
该应用程序在两种设备上都能正常运行,但有一件事情并非如此:
1。)单击相机按钮打开Android上的相机,我可以拍摄照片。选择“使用”后,照片将上传到服务器,屏幕将翻回概览,显示照片。
2。)在iOS上,整个应用程序在单击相机按钮时崩溃(当相机出现时)。所以相机甚至没有打开。在调试控制台上,我没有得到任何输出,因为调试器立即失去了与应用程序的连接。
可能是什么问题?下面我将我的代码用于此功能:
//get photo from camera
function getPhoto(source) {
var options;
if(source == 0)
{
var src = 'library';
}
else if(source == 1)
{
var src = 'camera';
}
sendImage(src, 'img1');
}
//upload photo to server
function sendImage(src, imagenr) {
// Set the image source [library || camera]
src = (src == 'library') ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.CAMERA;
// Aquire the image -> Phonegap API
navigator.camera.getPicture(success, fail, {quality: 20, allowEdit: true, sourceType: src, destinationType : Camera.DestinationType.DATA_URL});
// Successfully aquired image data -> base64 encoded string of the image file
function success(imageData) {
if(db.getItem("siteaudit") != ""){
var url = db.getItem("saurl")+"section_faults_image_upl.php";
}else{
var url = db.getItem("url")+"section_faults_image_upl.php";
}
var params = {};
params.uid = db.getItem('uid');
params.sid = db.getItem('location');
params.guid = db.getItem('faultID');
params.file = imageData;
// send the data
$.ajax({
type: "POST",
url: url,
data: params,
async: false,
username: db.getItem("user"),
password: db.getItem("pass"),
xhrFields: { withCredentials: true },
dataType: "html",
success: function(data, status, object){
var body = object.responseText;
//alert(body);
var filepath = db.getItem("url_base")+body;
//alert(filepath);
db.setItem(imagenr, filepath);
$('#'+imagenr).attr('src',filepath);
$('#a'+imagenr).attr('href',filepath).vanillabox({
animation: 'none',
closeButton: false,
keyboard: false,
loop: false,
preferredWidth: 640,
preferredHeight: 480,
repositionOnScroll: true,
type: 'image',
adjustToWindow: 'both'
});
if(imagenr == "img6")
{
$('#uplImgCamera').addClass("ui-disabled");
$('#uplImgGallery').addClass("ui-disabled");
}
},
error: function(e){
navigator.notification.alert('Status 184: '+e.status+' '+e.statusText, function(){}, 'Error...', 'Close');
}
});
}
function fail(message) { alert(message); }
}
提前感谢您对可能出现的问题的任何想法...
修改:
在使用断点进行过多调试后,只需提供一些其他信息:
问题似乎在于这一行:
navigator.camera.getPicture(success, fail, {quality: 20, allowEdit: true, sourceType: Camera.PictureSourceType.CAMERA, destinationType : Camera.DestinationType.DATA_URL});
我也尝试过popoverOptions:
navigator.camera.getPicture(success, fail, {quality: 20, allowEdit: true, sourceType: Camera.PictureSourceType.CAMERA, destinationType : Camera.DestinationType.DATA_URL, popoverOptions: new CameraPopoverOptions(300,300,100,100,Camera.PopoverArrowDirection.ARROW_ANY)});
正是在执行此行时,应用程序崩溃并关闭。
答案 0 :(得分:1)
我刚刚通过以下步骤解决了这个问题:
1.) organized me a MacBook Pro with Yosemite installed
2.) installed 5.1.1 version of Cordova (npm install -g cordova)
3.) created a new Cordova project
4.) added plugins and platform for iOS
5.) copied the www folder of old project to the www folder in the new project
6.) opened project in Xcode 6.4, added certificate, provision profile and all other resources like icons and splash images
7.) built the project and tested it on iOS 8.4 (iPad 4)
现在,相机插件的工作方式与iOS设备上的预期相同。我宁愿选择旧环境(Xcode 5.1和Cordova 4.2.0)的解决方案,但最后它现在可以使用。
希望,我可以帮助别人安全一天...