SLComposeViewController会崩溃

时间:2017-04-06 03:24:28

标签: ios objective-c xcode facebook

一个奇怪的错误,我使用以下代码在Facebook上分享一些

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

[slComposeViewController setInitialText:@"text"];
[slComposeViewController addImage:[UIImage imageNamed:@"image"]];
[self presentViewController:slComposeViewController animated:YES completion:nil];
} else {
 NSLog(@"Facebook not available");
}

如果在ios设置下没有facebook帐户,并且没有Facebook应用程序,则上面的代码运行良好,显示日志' Facebook不可用',但如果没有在ios设置下的facebook帐户,并且有facebook app,上面的代码会崩溃。还有其他办法吗?

1 个答案:

答案 0 :(得分:0)

您可以改用FBSDK。 here is the tutorial link

let content = FBSDKShareLinkContent()
            content.contentURL = NSURL(string: "http://share.html?id=\(1)&type=0")

            content.contentDescription = "here goes your description"



            content.imageURL = NSURL(string: "\(API_BASE_URL)\(primaryImagepath)")


            dialog.shareContent = content
            if  dialog.canShow() {
                dialog.show()
            }else{
                dialog.mode = .FeedBrowser
                dialog.show()
            }