About “SLComposeViewController” in iOS 11 beta

一笑奈何 提交于 2019-11-27 19:19:09

问题


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?


回答1:


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!




回答2:


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 :-(




回答3:


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.



来源:https://stackoverflow.com/questions/44879798/about-slcomposeviewcontroller-in-ios-11-beta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!