0

I am using an instance of UIActivityViewController in a universal app. It works absolutely perfectly on the iPad. Nearly, but not quite on the iPhone.

I present it using:

    [self presentViewController:self.activityViewController animated:YES completion:nil];

It displays the available activities correctly and if I choose one, it works. I can then tap on the Share button again and repeat with the same or a different activity as often as I like, so long as I complete the activity.

If I Cancel from the UIActivityViewController, all is well; but if I cancel from, say, Mail or Message, the next time I tap on Share, nothing happens. If I get impatient and tap again, I get the following error:

'Application tried to present modally an active controller .'

I've tried dismissing the controller before presenting it a second time, but it doesn't think it is dismissible. I've also tried presenting it from the root/navigation controller as well as the tableviewcontroller, but get the equivalent error (i.e. the app tried to present the root controller).

I see there are lots of 'odd' problems with UIActivityViewController, but I can't see anything relevant to my problem.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Nick
  • 4,820
  • 18
  • 31
  • 47
  • I'm not sure of the value of editing my OP to add a few full-stops and an irrelevant tag (there's no mention of UIActivityIndicatorView in my OP). Any suggestions to fix the problem much more appreciated! Bizarrely, you need 2k reputation to reject erroneous edits on my own posts! – Nick Apr 06 '14 at 18:31
  • It looks like you reference and hold your activityViewController as a property. That could be the issue here; have you checked to see that there aren't multiple instances of self.activityViewController elsewhere in the stack? – klcjr89 Apr 06 '14 at 20:02
  • Thanks for the suggestion. I'm fairly sure I'm not getting multiple instances. I use a getter that instantiates the property: `- (UIActivityViewController *)activityViewController { if ( !_activityViewController ) { _activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self] applicationActivities:nil]; } return _activityViewController; }` It also works perfectly on iPad and the only difference is in the presentation: – Nick Apr 08 '14 at 07:23

2 Answers2

1

The problem was due to the example code I'd used. I assumed that the dismiss code was being executed, when it wasn't!

I ended up implementing UIPopoverControllerDelegate and implementing:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    [self setPopoverActivity:nil];
}

This fixed it!

Nick
  • 4,820
  • 18
  • 31
  • 47
0

this happened to me too, i saw your answer and i didn't understand it, because that "setPopoverActivity" wasn't recognized. So i started do some changes and this solved just doing the init of the "UIActivityViewController" inside the action void instead on viewDidLoad, where it was at first place.

- (void) flipView {
    self.activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:self.dataToShare
                                      applicationActivities: nil];
    self.activityViewController.excludedActivityTypes = @[UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList];

    [self presentViewController:self.activityViewController animated:YES completion:nil];

}

Hope it helps!

Sonia Casas
  • 801
  • 9
  • 18
  • Hi. Thanks. the setPopoverActivity was a setter for the popoverActivity property I was using to hold the controller instance. – Nick May 01 '14 at 21:15