繁体   English   中英

Xcode Swift 4 Facebook和Twitter共享不再有效?

[英]Xcode Swift 4 Facebook & Twitter sharing no longer working?

我在我的应用程序中使用Facebook和Twitter共享,在将xCode升级到9.0.1 Swift 4之后,两者都无法正常工作,该方法说我的设备上没有FB或Tw帐户,但它们已经存在且工作正常斯威夫特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)

            }

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

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

文森特

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

您必须使用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开发者

Twitter iOS开发者页面

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM