17

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?

TheNeil
  • 3,321
  • 2
  • 27
  • 52
hujie
  • 181
  • 1
  • 1
  • 4

3 Answers3

20

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!

  • This works - if the user is not logged in, the composer will still pop up but then a "you need to log in" alert displays over it. – davedavedave Oct 30 '17 at 15:26
  • 1
    Is this solution working for people in the (iPhone) simulator when setting the deployment target to iOS11? It doesn't crash or anything but I don't get the actionsheet I get for iOS10 and below, and in the console it says `ViewDidAppear, but remote VC failed, dismissing` and `Sheet not being presented, calling premature completion`? – Louis Leung Nov 10 '17 at 01:32
  • 1
    Still working with twitter for me as shown here. Running on an iPad Air and iOS 11.2.2. – dodgy_coder Jan 31 '18 at 12:42
  • 1
    @matheus this is not working of LinkendIn,i there any other way – Satheeshkumar Naidu Jul 20 '18 at 05:50
  • @SatheeshkumarNaidu Which way do you have it? – Matheus Domingos Jan 24 '19 at 12:40
13

iOS 11 removed access to 3rd party accounts (such as Facebook and Twitter) through the Settings App. I’m currently struggling with the same thing.

You now must integrate the functionality with the SDK from the 3rd party. Twitter has a migration page here about steps to take:-

https://dev.twitter.com/twitterkit/ios/migrate-social-framework

I’ve yet to find specific instructions about how to migrate other social networks, but it’s safe to say it will require their 3rd party SDK.

No more easy out-the-box social sharing :-(

user8315745
  • 1,876
  • 1
  • 8
  • 3
  • 2
    SLComposeViewController is working fine for me, just as before. Check out the answer posted by Matheus. – Leon Oct 04 '17 at 16:09
  • Unfortunately, since the time of this answer, Twitter have discontinued their support for Twitter Kit, which means it's now even harder to have a simple best-practice for integrating with Twitter: https://blog.twitter.com/developer/en_us/topics/tools/2018/discontinuing-support-for-twitter-kit-sdk.html. – TheNeil May 15 '19 at 14:05
  • It looks like Twitter's API endpoints are the expected alternative now: https://developer.twitter.com/en/docs/tweets/post-and-engage/overview – TheNeil May 15 '19 at 14:17
6

For iOS 11 this line:

 ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 

is always returning NO

I replaced it with check if user has Facebook app installed with:

static NSString *const canOpenFacebookURL = @"fbauth2";

+ adding it to LSApplicationQueriesSchemes in plist

-(BOOL)isFacebookAppInstalled {
    NSURLComponents *components = [[NSURLComponents alloc] init];
    components.scheme = canOpenFacebookURL;
    components.path = @"/";
    return [[UIApplication sharedApplication]
            canOpenURL:components.URL];
}

And then just call SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

as usual, the same how Matheus Domingos described. But with this check at least you know that user has facebook app installed.

bekzattt
  • 61
  • 1
  • 1
  • 1
    This works, but is it 'safe'? Why are the SLServiceType constants deprecated, but SLComposeViewController is not? Why does this still work? :) – Thomas Clowes Jun 03 '19 at 10:43