Can't keep open the "open with" menu invoked from UIDocumentInteractionController (iPad iOS 8+)

207 views Asked by At

I'm developing an iOS app for iPhone and iPad, and I have an issue.

This is the code attached to a UIBarButton.

- (IBAction)saveFile:(id)sender {

  NSURL *theRessourcesURL = [[self.webView request] URL];
  NSString *filename = [theRessourcesURL lastPathComponent];
  NSString *docPath = [self documentsDirectoryPath];
  NSString *pathToDownloadTo = [NSString stringWithFormat:@"%@/%@", docPath, filename];

  NSData *tmp = [NSData dataWithContentsOfURL:theRessourcesURL];
  // Save the loaded data if loaded successfully
  if (tmp != nil) {
    NSError *error = nil;
    // Write the contents of our tmp object into a file
    [tmp writeToFile:pathToDownloadTo options:NSDataWritingAtomic error:&error];
    if (error != nil) {
      // Display an UIAlertView that shows the users we don't saved the file
      UIAlertView *filenameAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Report don't saved",nil) message:[self titleAlert:filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
      [filenameAlert show];
    }
  } else {
    // Display an UIAlertView that shows the users we don't saved the file
    UIAlertView *filenameAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Report don't saved",nil) message:[self titleAlert:filename] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
   [filenameAlert show];
  }

 // "Open it and options.." menu
 self.menuController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pathToDownloadTo]];
 self.menuController.delegate = self;
 [self.menuController presentOpenInMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
 [self.menuController presentOptionsMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
}

This builds with no issues, and running under iOS 7, this code works fine.

The problem is that, in iOS 8+, when running on iPad it show this warning:

LaunchServices: invalidationHandler called
Warning: Attempt to present <_UIDocumentActivityViewController: 0x1601004c0> on <UINavigationController: 0x15cd9a650> while a presentation is in progress!

and on the interface the "open with.." menu show and hide quickly and the user can't select any option on the menu. On iPhone that warnings appears too, but the "open with.." menu works correctly.

0

There are 0 answers