Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

ipad openPhotoGallery popover control

This Works (hacked together from different parts of kitchen sink)

Titanium 1.2.1
iPad Version 4
Not sure about the SDK version, I think its the latest though (I went and manually DL'd it tonight, installed it, and then it downloaded some more stuff).


//
// create base UI tab and root window
//
var win = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});


var imageView = Titanium.UI.createImageView({
    height:200,
    width:200,
    top:20,
    left:10,
    backgroundColor:'#999'
});

win.add(imageView);

var popoverView;
var arrowDirection;

if (Titanium.Platform.osname == 'ipad')
{
    // photogallery displays in a popover on the ipad and we 
    // want to make it relative to our image with a left arrow
    arrowDirection = Ti.UI.iPad.POPOVER_ARROW_DIRECTION_LEFT;
    popoverView = imageView;
}

Titanium.Media.openPhotoGallery({

    success:function(event)
    {    
    },
    cancel:function()
    {

    },
    error:function(error)
    {
    },
    allowImageEditing:true,
    //popoverView:popoverView,
    arrowDirection:arrowDirection,
});


// open tab group
win.open();

You'll notice at the bottom, the popoverView is commented out.

If I used this popoverView property in any way whatsoever, it hits the fan.

What gives?

— asked July 28th 2010 by Ken Hanson
  • ipad
  • openphotogallery
  • photo
3 Comments
  • To Clarify: I just want to be able to position / resize / adjust the dang popover o_O.

    I also don't know how to get logs of why the thing crashes. In the Titanium logs, all it says is:

    [INFO] Launched application in Simulator (0.89 seconds)
    [DEBUG] Session started
    [DEBUG] Session did end with error Error Domain=DTiPhoneSimulatorErrorDomain Code=1 UserInfo=0x1003041f0 "The simulated application quit."
    [INFO] Application has exited from Simulator
    

    The behavior is: Titanium launches the simulator, then i see the app load screen, then I'm on the iPad "desktop" with icons.

    Another REAALLY weird thing, is that the apps available while running Titanium are all iPhone, including the photos app, which just blows me away haha. If I launch the photos app, its in 1x/2x mode o_O, and its the iPad simulator.

    — commented July 28th 2010 by Ken Hanson
  • Ok, more notes:
    I'm Definitely on 4.0 SDK

    And I finally got a stack trace:

    [ERROR] The application has crashed with an unhandled exception. Stack trace:
    0 CoreFoundation 0x036308fc __exceptionPreprocess + 156
    1 libobjc.A.dylib 0x0377e5de objc_exception_throw + 47
    2 CoreFoundation 0x035e9078 +[NSException raise:format:arguments:] + 136
    3 CoreFoundation 0x035e8fea +[NSException raise:format:] + 58
    4 UIKit 0x00b69db4 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 213
    5 Shutter Bug 0x000ce0f1 -[MediaModule displayModalPicker:settings:] + 670
    6 Shutter Bug 0x000cf04b -[MediaModule showPicker:isCamera:] + 3716
    7 Shutter Bug 0x000d11c6 -[MediaModule openPhotoGallery:] + 694
    8 Foundation 0x00582e9a __NSThreadPerformPerform + 251
    9 CoreFoundation 0x03611d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    10 CoreFoundation 0x035702cb __CFRunLoopDoSources0 + 571
    11 CoreFoundation 0x0356f7c6 __CFRunLoopRun + 470
    12 CoreFoundation 0x0356f280 CFRunLoopRunSpecific + 208
    13 CoreFoundation 0x0356f1a1 CFRunLoopRunInMode + 97
    14 GraphicsServices 0x04e1b2c8 GSEventRunModal + 217
    15 GraphicsServices 0x04e1b38d GSEventRun + 115
    16 UIKit 0x00811b58 UIApplicationMain + 1160
    17 Shutter Bug 0x00003def main + 362
    18 Shutter Bug 0x00002da1 start + 53
    2010-07-28 05:09:11.396 Shutter Bug[12669:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'
    *** Call stack at first throw:
    (
    0 CoreFoundation 0x03630919 __exceptionPreprocess + 185
    1 libobjc.A.dylib 0x0377e5de objc_exception_throw + 47
    2 CoreFoundation 0x035e9078 +[NSException raise:format:arguments:] + 136
    3 CoreFoundation 0x035e8fea +[NSException raise:format:] + 58
    4 UIKit 0x00b69db4 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 213
    5 Shutter Bug 0x000ce0f1 -[MediaModule displayModalPicker:settings:] + 670
    6 Shutter Bug 0x000cf04b -[MediaModule showPicker:isCamera:] + 3716
    7 Shutter Bug 0x000d11c6 -[MediaModule openPhotoGallery:] + 694
    8 Foundation 0x00582e9a __NSThreadPerformPerform + 251
    9 CoreFoundation 0x03611d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    10 CoreFoundation 0x035702cb __CFRunLoopDoSources0 + 571
    11 CoreFoundation 0x0356f7c6 __CFRunLoopRun + 470
    12 CoreFoundation 0x0356f280 CFRunLoopRunSpecific + 208
    13 CoreFoundation 0x0356f1a1 CFRunLoopRunInMode + 97
    14 GraphicsServices 0x04e1b2c8 GSEventRunModal + 217
    15 GraphicsServices 0x04e1b38d GSEventRun + 115
    16 UIKit 0x00811b58 UIApplicationMain + 1160
    17 Shutter Bug 0x00003def main + 362
    18 Shutter Bug 0x00002da1 start + 53
    )
    terminate called after throwing an instance of 'NSException'
    [DEBUG] Session did end with error (null)
    [INFO] Application has exited from Simulator
    
    — commented July 28th 2010 by Ken Hanson
  • This bit here looks really promising…

    2010-07-28 05:09:11.396 Shutter Bug[12669:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.
    

    But how to fix it?

    Also, is there a way to open the photogallery without using popovers?! I'll take any creative ideas at this point ha!

    — commented July 28th 2010 by Ken Hanson

1 Answer

  • I feel a bit silly… but such is the nature of diving in and hacking something together!

    I got it working!

    This guy needs to come first, before the openPhotoGallery is called:

    win.open();
    

    I was basing my examples off of the generated + the photo_gallery.js in KitchenSink. Looking over it now that I know the problem, it makes sense. the Kitchen Sink version has already called win.open at some point, earlier in the menu walks.

    Hewray! I was really wanting to love Titanium, and now I still get to :D

    — answered July 28th 2010 by Ken Hanson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.