About "SLComposeViewController" in iOS 11 beta

hujie picture hujie · Jul 3, 2017 · Viewed 10.9k times · Source

In my project, I always use SLComposeViewController to share contents with third-party apps, but now, when I update my iPhone to iOS 11 beta, this no longer works.

The SLComposeViewControllerCompletionHandler always callback SLComposeViewControllerResultCancelled.

Why is this?

Answer

Matheus Domingos picture Matheus Domingos · Oct 4, 2017

I was having problems with regard to the SLComposer in iOS 11. But I just removed the line that checks and apparently the own SDK makes the validacoes to me internally.

Remove this line serves for any SLServiceType:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

So, develop your logic. In my case:

SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [mySLComposerSheet setInitialText:@"#myInitialTextIsHere"];
        [mySLComposerSheet addURL:[NSURL URLWithString:strURL]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

            switch (result) {
                case SLComposeViewControllerResultCancelled:
                    NSLog(@"Post Canceled");
                    break;
                case SLComposeViewControllerResultDone:
                    NSLog(@"Post Sucessful");
                    break;

                default:
                    break;
            }
        }];

        [self presentViewController:mySLComposerSheet animated:YES completion:nil];

I hope I have helped!