Social Framework iOS 8 swift

耗尽温柔 提交于 2019-12-05 03:42:48

Try the following code, not yet tested

 socialVC.completionHandler = {
    (result:SLComposeViewControllerResult) in
        // Your code
    }
    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)
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!