LaunchServices: invalidationHandler called - iOS 8 share sheet

吃可爱长大的小学妹 提交于 2019-11-29 05:28:14
Ram G.

Add this code after you present your activity view controller:

if ([activityVC respondsToSelector:@selector(popoverPresentationController)])
{
    // iOS 8+
    UIPopoverPresentationController *presentationController = [activityVC popoverPresentationController];

    presentationController.sourceView = sender; // if button or change to self.view.
}

Looking at the developer forums: "That log message does not indicate any error on your part."

I had a similar problem with a UIDocumentInteractionController, where when I tapped outside it to dismiss it, or selected another app to open the document in, it would crash with the "LaunchServices: invalideationHandler called" console message displayed twice (only using iOS 8).

A workaround is to add the call to presentOpenInMenuFromRect:inView:animated to the main queue, i.e.

dispatch_async(dispatch_get_main_queue(), ^() {

[self.documentInteraction presentOpenInMenuFromRect:theRect inView:self.view animated:YES];

});

You may also need to define the sourceRect. I used the following code to display a SLComposeViewController from a tableView.

if ([controller respondsToSelector:@selector(popoverPresentationController)]) {
    //get rect for this row in table
    CGRect frame = [self.tableView rectForRowAtIndexPath:indexPath];

    //convert table row frame to view reference
    CGRect frameInView = [self.tableView convertRect:frame toView:self.view];

    [controller popoverPresentationController].sourceRect = frameInView;
    [controller popoverPresentationController].sourceView = self.view;
}

Regarding the auto-closing (not the crash): I think it's probably related to the link you are trying to share. I'm seeing the same thing when trying to post music links (Spotify, SoundCloud,...). The same tweet works if I replace the link by a link to some non-media-content. I'll file radar on this to see whether it's intentional...

This gets rid of the Error message for me and works as expected. You have to get rid of the if statement that calls "isAvailableForServiceType:"

It should look like this. Happy coding.

    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:SLServiceTypeTwitter];

    [tweetSheet setInitialText:@"Great fun to learn iOS programming at appcoda.com!"];
    [self presentViewController:tweetSheet animated:YES completion:nil];

    if ([tweetSheet respondsToSelector:@selector(popoverPresentationController)])
    {
        // iOS 8+
        UIPopoverPresentationController *presentationController = [tweetSheet popoverPresentationController];

        presentationController.sourceView = sender; // if button or change to self.view.
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!