【发布时间】:2016-11-30 10:09:40
【问题描述】:
我使用 Appcelerator (Titanium SDK) 制作应用程序。 打开相机时出现问题,我已经在tiapp.xml中设置了相机权限。 我已经尝试使用厨房水槽钛的来源。
这是我的代码
var win;
function fireUpTheCamera() {
if (Ti.Platform.osname === 'android'|| Ti.Platform.osname == "iphone" || Ti.Platform.osname == 'ipad') {
win.removeEventListener('focus', fireUpTheCamera);
}
Titanium.Media.showCamera({
success:function(event) {
var cropRect = event.cropRect;
var image = event.media;
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
var imageView = Ti.UI.createImageView({
width:win.width,
height:win.height,
image:event.media
});
win.add(imageView);
}
else
{
alert("got the wrong type back ="+event.mediaType);
}
},
cancel:function() {
},
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();
},
saveToPhotoGallery:true,
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
}
function cam_basic(_args) {
win = Titanium.UI.createWindow({
title:_args.title
});
if (Ti.Platform.osname === 'android'|| Ti.Platform.osname == "iphone" || Ti.Platform.osname == 'ipad') {
win.addEventListener('focus', fireUpTheCamera);
} else {
fireUpTheCamera();
}
return win;
};
module.exports = cam_basic;
当我完成捕获图片并按下确定按钮时,它总是重新启动应用程序而没有任何错误消息,也在日志中。
我正在使用 SDK 6.0.0GA。
请给我一些帮助,我的代码出了什么问题。
【问题讨论】:
-
在回调中删除代码时,它仍然有效吗?
-
@RenePot 我已经尝试删除回调,并且仍然强制关闭而不会收到任何错误。
标签: android titanium appcelerator titanium-mobile