I am building an application for iOS and Android using Appaccelerator. It works perfectly fine on Android, but throws 'undefined' error every time I try to open it on iOS devices. The weird thing is, it doesnt show a proper error message.
First I thought it is a build issue, so I cleaned the project, and then rebuilt it, but it was not the case. I also manually deleted the build folder, and rebuild, but still no improvement.
Here is the code :
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() { }, }); } };I get this error.
[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";
4 Answers
Accepted Answer
This one fascinated me, so I took some time and compiled it myself. It looks like the compiler just isn't detecting that you're using Ti.Media because it's inside a function in an object. This would be a great JIRA ticket to file.
The workaround, I found, is to just put this anywhere in your code, at the top level. I put it just before the Rf.media.photo definition:
var test = Ti.Media.fireEvent('hi');
This got the compiler to include Ti.Media.
have you tried cleaning and rebuilding your app? This happens sometimes when you first add new namespaces to your project Ti.Media
I think it's because you have "Ti.media.showCamera" instead of "Ti.Media.showCamera"
I also has faced this issue,This is nothing,But your Titanium SDK Version Problem,Chenge your SDK Version,and it would work Perfectly fine.Dnt remeber the exact SDK Version,So you just change your SDK Version,It Would work.
Thanks.
Your Answer
Think you can help? Login to answer this question!