Question

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.

Was it helpful?

Solution

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!

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top