Social Framework iOS 8 swift

。_饼干妹妹 提交于 2020-01-02 02:18:12

问题


So I've been writing an app that needs to use Social framework to share text via twitter and facebook.

I got it to work but it did not dismiss (?), then I remembered the completion handler, but whatever I do this handler keeps on giving me errors.

var okFacebook :Bool = SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook)
var okTwitter :Bool = SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter)
var okLinkedIn : Bool = SLComposeViewController.isAvailableForServiceType(SLServiceTypeLinkedIn)
var socialVC :SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)

socialVC.completionHandler = SLComposeViewControllerCompletionHandler(SLComposeViewControllerResult) -> Void
self.presentViewController(socialVC, animated: true, completion: nil)

回答1:


Try the following code, not yet tested

 socialVC.completionHandler = {
    (result:SLComposeViewControllerResult) in
        // Your code
    }



回答2:


    override func viewDidLoad() {
    super.viewDidLoad()

    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
        var facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)


        facebookSheet.setInitialText("Hiya, I have just discovered this great app called Dwingle, which I think you're going to love.")
        let url = NSURL(string: "")
        facebookSheet.addURL(url)
        self.presentViewController(facebookSheet, animated: true, completion: nil)


        facebookSheet.completionHandler = {

            result -> Void in
            self.dismissViewControllerAnimated(true, completion: { () -> Void in
                self.navigationController?.popToRootViewControllerAnimated(true)
            })
        }


    } else {
        var alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
    }
}


来源:https://stackoverflow.com/questions/24528854/social-framework-ios-8-swift

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