Xcode Swift 4 Facebook& Twitter分享不再有效?

时间:2017-10-25 06:55:09

标签: ios xcode facebook twitter

我正在使用Facebook& Twitter在我的应用程序中共享,在将xCode升级到9.0.1 Swift 4之后,两者都无法正常工作,该方法说我的设备上没有FB或Tw帐户,但他们已经在那里并且与Swift 3一起工作正常。

记录:

2017-10-25 09:53:41.619676+0300 jack[2428:926750] [core] isAvailableForServiceType: for com.apple.social.facebook returning NO

这是代码:

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook)
            {

                let shareText = "xxx"

                let facebookShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
                    //facebookShare.add(imageView.image!)
                    facebookShare.add(URL(string:self.track.share_url))
                    facebookShare.setInitialText(shareText)

                self.present(facebookShare, animated: true, completion: nil)

            }

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter)
            {
                let shareText = "xxx"
                let twitterSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
                    twitterSheet.add(URL(string : self.track.share_url))
                    twitterSheet.setInitialText( shareText )

                self.present(twitterSheet, animated: true, completion: nil)

            }

3 个答案:

答案 0 :(得分:2)

iOS 11已禁用这些功能。您不应再在iOS设置应用中看到Facebook NOR twitter子菜单。

我建议您使用常规共享选项或fb / twitter API。

文森特

答案 1 :(得分:1)

不要再检查它是否可用; isAvailable(forServiceType :),直接运行它。我自己也面临类似的问题

答案 2 :(得分:0)

您必须使用Facebook的SDK共享:FBSDKShareKit

您可以使用可可豆荚安装它:

pod 'FBSDKShareKit'

实施例

#import <FBSDKShareKit/FBSDKShareKit.h>

-(IBAction)sharingOnFacebook:(id)sender {
     FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
     content.contentURL = [NSURL URLWithString:@"https://myPageWeb/"];

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];
}

对于Twitter,步骤类似:TwitterKit

pod 'TwitterKit'

示例:

-(IBAction)sharingOnTwitter:(id)sender {
    TWTRComposer *composer = [[TWTRComposer alloc] init];
    [composer setURL:[NSURL URLWithString:@"https://https://myPageWeb/"]];
    [composer showFromViewController:self completion:^(TWTRComposerResult result) {
        /*if (result == TWTRComposerResultCancelled) {
            NSLog(@"Tweet composition cancelled");
        } else {
            NSLog(@"Sending Tweet!");
        }*/
    }];
}

注意:阅读Facebook和Twitter文档,因为您需要先为您的应用做一些步骤。注册应用程序,获取AppID ...

Facebook iOS Developers

Twitter iOS Developers page