I can't share a content from my iOS app to the Facebook when Facebook app is installed

流过昼夜 提交于 2019-12-11 13:35:56

问题


if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        imageUser.hidden=NO;
//            [imageUser sendSubviewToBack:_horizontalScrollView];

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];


        UIImage *goImage=[[UIImage alloc]init];
        goImage=[self scaleImage:image123];

        [controller setInitialText:@"Check out my pic from "];
        [controller addURL:[NSURL URLWithString:@"www.awesomeapp.com"]];
        [controller addImage:goImage];
        imageUser.hidden=YES;

        [self presentViewController:controller animated:YES completion:Nil];
    }

I have gone through many stackoverflow questions and tried almost all. Some users reported it as bug, If so do we have any other way through which I can achieve my goal. It works like charm when Facebook app is not there but when the app is there this won't work :

    [controller addURL:[NSURL URLWithString:@"www.awesomeapp.com"]];

Please help me achieve my goal. Thanks in advance.


回答1:


I too headed up with is problem,some how i managed with FBSDKShareKit

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
        FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
        NSString * UrlString = [NSString stringWithFormat:@"https://www.google.co.in/"];
                                NSString * Subject = [NSString stringWithFormat:@"FBSDKShareKit is an alternative to this issue"];
        content.contentURL = [NSURL URLWithString:UrlString];
        content.contentTitle = @"FBSDKShareKit";
        content.contentDescription = Subject;
        content.imageURL = [NSURL URLWithString:@"https://i.vimeocdn.com/portrait/58832_300x300.jpg"];
        FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
        dialog.fromViewController = self;
        dialog.shareContent = content;
        dialog.mode = FBSDKShareDialogModeFeedBrowser;
        [dialog show];
}else{
    //Go with your own method to share in FaceBook
}

In my pod file:

pod 'FBSDKShareKit', '~> 4.6.0'

dialog.mode = FBSDKShareDialogModeFeedBrowser it opens a fbShareDialog within your app which consist of all given datas. Try some other alternatives for mode such as FBSDKShareDialogModeShareSheet,FBSDKShareDialogModeBrowser,FBSDKShareDialogModeWeb... it may also help you. I found FBSDKShareDialogModeFeedBrowser as satisfying. Try it,Let me know whether it works or not.



来源:https://stackoverflow.com/questions/37320157/i-cant-share-a-content-from-my-ios-app-to-the-facebook-when-facebook-app-is-ins

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