Ti.media.showCamera throws 'undefined' error on iPhone but works fine on Android

You must Login before you can answer or comment on any questions.

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

— answered 9 months ago by Aaron Saunders
answer permalink
1 Comment
  • I both cleaned and rebuilt it several times, but the error is still there. I get the error on actual iPhone (Both on 3GS and 4S). I think that it doesnt load Ti.Media at all, could that be the case?

    — commented 9 months ago by Kristaps Horns

I think it's because you have "Ti.media.showCamera" instead of "Ti.Media.showCamera"

— answered 9 months ago by Shannon Hicks
answer permalink
1 Comment
  • I just changed "Ti.media.showCamera" into "Ti.Media.showCamera" ,cleaned the project. Rebuilt and I am still getting the same error.

    — commented 9 months ago by Kristaps Horns

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.

— answered 9 months ago by pankaj Goyal
answer permalink
1 Comment
  • I already changed it today to the newest 2.1.2.GA ,but it did not solve the issue, I am currently rebuilding the app using solution provided by Shannon Hicks, and will post results here ASAP.

    — commented 9 months ago by Kristaps Horns

Your Answer

Think you can help? Login to answer this question!