Just Updated to the 6.0 ioS SDK - Problems with openPhotoGallery

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

Hi

I have just upgraded my xCode to the latest 4.5 with the latest ios6 SDK. I also have Titanium fully updated to the latest 2.1.3 GA.

My iPad app is now suffering from a problem with the openPhotoGallery method. My app runs in landscape mode only.

This worked perfectly fine beforehand but now i get no response after clicking the choosePhotoButton and it causes everything else in the app to freeze so no other buttons etc work

I have the following code setup:

// Create empty iPad popover
var choosePhotoPopover; 
 
// Create dummy anchor point to fix popovers position on screen
var choosePhotoPopoverAnchor = Ti.UI.createImageView({
    width:1, height:1, top:51, left:513, opacity:0
});
 
// Create view to go inside iPad popover 
var choosePhotoPopoverView = Ti.UI.createView({
    width:320,height:200, backgroundImage:'/images/view.png'
});
 
// Create camera button
var takePhotoButton = Titanium.UI.createButton({
    width:160, height:200, top:0, left:0, backgroundImage:'/images/camera_btn.png'
});
 
// Create choose photo button   
var choosePhotoButton = Titanium.UI.createButton({
    width:160, height:200, top:0, right:0, backgroundImage:'/images/photo_btn.png'
});
 
// Add buttons to popover view   
choosePhotoPopoverView.add(takePhotoButton);
choosePhotoPopoverView.add(choosePhotoButton);
 
// Add Photo Button Listener - on click create actual popover or show existing  
addPhotoButton.addEventListener('click', function(){
        if(!choosePhotoPopover){
            choosePhotoPopover = Ti.UI.iPad.createPopover({width:320,height:160, arrowDirection:Ti.UI.iPad.POPOVER_ARROW_DIRECTION_UP, navBarHidden:true});
            choosePhotoPopover.add(choosePhotoPopoverView);
            choosePhotoPopover.show({view:choosePhotoPopoverAnchor});
        }
        else {
            choosePhotoPopover.show({view:choosePhotoPopoverAnchor});
        }
    });
Then the actual opening of the photo gallery:
// attached click listener to the choose photo button thats within the iPad popover
    choosePhotoButton.addEventListener('click', function() {
        choosePhotoPopover.hide();
        Ti.Media.openPhotoGallery({
            success:function(event) {
                // start another function...    
            },
            cancel:function() {},
            error:function(error) {
                alert('Camera Reel Error');
            },
        mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
        });
    });
Can anyone please help??

— asked 8 months ago by Javier Perrera
3 Comments
  • Confirm, I have the same problem with openPhotoGallery on iPad landscape.

    — commented 8 months ago by Sandro Lain

  • Have you had any luck or ideas about a possible solution or the cause of it Sandro??

    — commented 8 months ago by Javier Perrera

  • Cause or solution no for now, but in my case I have seen that by inserting an alert before openPhotoGalley returns to work. I also tried to set a setInterval with a log in the console to see if the app was frozen, but it was not. It just seems that there is something that blocks access to the interface or related events.

    — commented 8 months ago by Sandro Lain

5 Answers

Just an update on this. Appcelerator have looked into this in jira:

see here

It's a bug in iOS6 and Apple rather than appcelerator as explained here with full explanation seen on the ticket link

PhotoGallery(UIImagePickerController) is a portrait-only view controller and in iOS 6 Apple has started enforcing this rule.
Short version being Landscape-only applications that invoke a portrait-only view controller (such as the Game Center sign-in screen or the UIImagePickerController) and are built using the iOS 6 SDK may crash/freeze up the UI.
The crash log may look like 
"*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'"
The interm solution, while Apple may fix this in the future release is to temporarily make container window in which the photogallery popover is to be attached to have a portrait orientation also included in them.

I also have the same problem..... found a JIRA Ticket for it..... and is marked resolved because they can't reproduce it......

— answered 8 months ago by Juan Rios
answer permalink
3 Comments
  • If the above test cases are reproducible, can you please add/comment on the JIRA ticket mentioned so we can fix it ASAP?

    — commented 8 months ago by Ingo Muschenetz

  • I tried the code in the app.js example of the ticket, and work. After removing the line alert('I will now call Ti.Media.openPhotoGallery'); does not work anymore! Then I tried to insert an alert before openPhotoGallery in the event listener of my app, and now works!

    — commented 8 months ago by Sandro Lain

  • I have been to use the test example from the jira ticket in my app. Like you say, It works with the alert in place but as soon as it's taken out it fails.

    Obviously having an alert everytime the user clicks this (which can be many times in my app just doesnt work - is there an explanation with why an alert needs to be there and also how to solve without it?

    — commented 8 months ago by Javier Perrera

Can anyone help with this? The example in the Jira ticket shows a solution but not by using an alert box - which 1. I cannot have in my app and 2. Seems like a very poor solution, I understand it may be a quick short term fix but m surprised its marked as resolved.

I am now in a position where my app fails to work as I have updated my test device to ios6 and developing using Xcode. 4.5 and seek 6 :(

i am also having a problem with this i posted my issue hear http://developer.appcelerator.com/question/144622/titaniummediaopenphotogallery-crashing-in-ios6 before i read this post it works with a alert but crashes without.

Whats the current status with this really need to get this sorted urgently

Thanks

Anyone having this problem this solution worked for me, wrap photo gallery around a empty window. Hope this doesn't cause any issues for older versions havent tested

var win = Ti.UI.createWindow({
    orientationModes: [Titanium.UI.LANDSCAPE_LEFT, Titanium.UI.LANDSCAPE_RIGHT]
});
win.addEventListener("open", function() {
    win.orientationModes = [Titanium.UI.LANDSCAPE_LEFT, Titanium.UI.LANDSCAPE_RIGHT, Titanium.UI.PORTRAIT];
    Ti.Media.openPhotoGallery({
        success: function(event) {
            // start another function...   
            win.close();
        },
        cancel: function() {
            win.close();
        },
        error: function(error) {
            win.close();
            alert('Camera Reel Error');
        },
        mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
    });
 
});
win.open();?

Your Answer

Think you can help? Login to answer this question!