1

I'm trying to add the "presentOpenInMenuFromRect" functionality to Rhomobile. However, I have trouble referencing to the current view.

The Rhomobile function (### marks my additions):

- (void)openDocInteractCommand:(NSString*)url {
if (NSClassFromString(@"UIDocumentInteractionController")) {
    NSURL *fileURL = [NSURL fileURLWithPath:url];

    UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];

    docController.delegate = self;//[AppManager instance];

    BOOL result = [docController presentPreviewAnimated:YES];

    if (!result) {
      ###
        BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
      ###
    }    
}
}

Essentially, if the preview fails, I want to open the "Open In" menu, because I;mtrying to open a .KMZ (Google Earth KML file) and it can't be previews.

Full source code: https://github.com/rhomobile/rhodes/blob/master/platform/iphone/Classes/AppManager/AppManager.m

Thanks,

Nick,

fnllc
  • 3,047
  • 4
  • 25
  • 42

2 Answers2

2

Here is the code solving my problem:

  - (void)openDocInteractCommand:(NSString*)url { // inView:(UIView*)view
if (NSClassFromString(@"UIDocumentInteractionController")) {
    NSURL *fileURL = [NSURL fileURLWithPath:url];

    UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];

    docController.delegate = self;//[AppManager instance];

    BOOL result = [docController presentPreviewAnimated:YES];

    if (!result) {
        [docController retain];
        CGPoint centerPoint = [Rhodes sharedInstance].window.center;
        CGRect centerRec = CGRectMake(centerPoint.x, centerPoint.y, 0, 0);
        BOOL isValid = [docController presentOpenInMenuFromRect:centerRec inView:[Rhodes sharedInstance].window animated:YES];
    }
}
}

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)docController
{
[docController autorelease];
}
fnllc
  • 3,047
  • 4
  • 25
  • 42
1

The AppManager class inherits from NSObject and not from UIViewController - how come it would have a property named view? You have to find another way to present your view or view controller (maybe use the application's main window).

  • Ok, I'm a newbie. Can you tell from the source how to get to the Main Window? I tried this: BOOL isValid = [docController presentOpenInMenuFromRect:CGRectMake(300, 300, 100, 100) inView:[Rhodes sharedInstance].window animated:YES]; but it gives this error: *** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.' --- I never saw the "Open In..." menu. – fnllc Aug 31 '12 at 23:11
  • @user506706 you can use [[UIApplication sharedApplication] keyWindow], but I think that's not quite relevant here... :( –  Sep 01 '12 at 11:48
  • Solved it using this solution: http://stackoverflow.com/questions/12222940/undefined-self-view-for-presentopeninmenufromrect – fnllc Sep 01 '12 at 13:20