objective-ccrashuidocumentinteractionuibuttonbaritem

UIDocumentInteractionController crash with presentOpenInMenuFromBarButtonItem: method


I tried to open a pdf file with the "Open in" menu, but when I create it, the code crash when I call the presentOpenInMenuFromBarButtonItem method

UIDocumentInteractionController * controller;
        controller = [UIDocumentInteractionController interactionControllerWithURL:fileUrl];
        controller.delegate = self;

        [controller presentOpenInMenuFromBarButtonItem:_openInBBItem animated:YES];

There is no error message.

Can you help me ?


Solution

  • The solution is to keep a reference on the UIDocumentInteractionController.

    .h

    @property UIDocumentInteractionController* interact;
    

    .m

    _interact = [UIDocumentInteractionController interactionControllerWithURL: fileUrl];
    _interact.delegate = self;
    [_interact presentOpenInMenuFromBarButtonItem: _openInBBItem animated:YES];