1
我正在使用Appaccelerator爲iOS和Android構建應用程序。它在Android上運行得非常好,但每次嘗試在iOS設備上打開它時都會拋出「未定義」錯誤。奇怪的是,它沒有顯示正確的錯誤信息。Ti.media.showCamera在iPhone上拋出'undefined'錯誤,但在Android上正常工作
首先,我認爲這是一個構建問題,所以我清理了該項目,然後重新構建了它,但事實並非如此。我也手動刪除了構建文件夾,並重建,但仍然沒有改進。
下面是代碼:
Rf.media.photo = {
key: 'photo',
title: 'Photo',
extension: 'jpg',
type: 'image/jpeg',
create: function(created) {
Ti.media.showCamera({
animated: false,
saveToPhotoGallery: false,
showControls: true,
success: function() {
var name = Rf.util.timestamp() + '.' + Rf.media.photo.extension;
Rf.write_to_new_file(name, media_item.media, function(file) {
created(file);
});
},
error:function(error)
{
// create alert
var a = Titanium.UI.createAlertDialog({title:'Camera'});
// set message
if (error.code == Titanium.Media.NO_CAMERA)
{
a.setMessage('Please run this test on device');
}
else
{
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
},
cancel:function()
{
},
});
}
};
我收到此錯誤信息,當人們clikc在「照片」按鈕。
[WARN] Exception in event callback. {
line = 1;
message = "'undefined' is not an object (evaluating 'Ti.Media.showCamera')";
name = TypeError;
sourceId = 52935904;
sourceURL = "file://localhost/var/mobile/Applications/F8398B04-78C4-4A45-BEE0-30EE4BFEBB00/App.app/photo.js";
有沒有辦法「初始化」Ti.Media.showCamera();方法,所以它不會發現自己'未定義'?