Search code examples
iosuidocumentinteraction

UIDocumentInteractionControllerDelegate check when document is loaded


Which delegate function of UIDocumentInteractionControllerDelegate is called when document is completely loaded on the preview?
Just to share, I have already tried :

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller  

And this is called when we close the preview.


Solution

  • This is a bit of a work around as there doesn't appear to be a completion handler for this in the documentation, as far as I can tell.

    -(void)presentDocument:(NSURL*)url{
            UIDocumentInteractionController *docInteration = [UIDocumentInteractionController interactionControllerWithURL:url];
            docInteration.UTI = @"com.adobe.pdf";
            docInteration.delegate = self;
            [docInteration presentPreviewAnimated:YES];
    }
    
    -(void)documentInteractionControllerDidEndPreview: (UIDocumentInteractionController *)controller{
        [self.navigationController dismissViewControllerAnimated:NO completion:nil];
    }
    
    - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
    
        UIViewController * vc = [[UIViewController alloc]init];
        [self.navigationController presentViewController:vc
                                                animated:YES
                                              completion:^{
                                                  //This is ran once the document animation has completed
                                              }];
        return vc;
    }
    

    Hope this helps.
    Luke