Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使我的SLComposeViewController可用于服务类型(Facebook)iOS swift_Ios_Swift_Facebook Share - Fatal编程技术网

如何使我的SLComposeViewController可用于服务类型(Facebook)iOS swift

如何使我的SLComposeViewController可用于服务类型(Facebook)iOS swift,ios,swift,facebook-share,Ios,Swift,Facebook Share,我刚刚添加了所有必需的Facebook框架,调整了我的info.plist,并在我的AppDelegate中添加了允许用户使用Facebook登录的方法。我甚至在我的parse数据库中测试和验证了这些新数据。耶 现在,我正在尝试添加一个按钮,如果用户通过Facebook登录到我的应用程序,该按钮将信息共享到用户的新闻提要中。以下是我所拥有的: @IBAction func tellFriends(sender: AnyObject) { if SLComposeViewControll

我刚刚添加了所有必需的Facebook框架,调整了我的info.plist,并在我的AppDelegate中添加了允许用户使用Facebook登录的方法。我甚至在我的parse数据库中测试和验证了这些新数据。耶

现在,我正在尝试添加一个按钮,如果用户通过Facebook登录到我的应用程序,该按钮将信息共享到用户的新闻提要中。以下是我所拥有的:

@IBAction func tellFriends(sender: AnyObject) {

    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {  // USER LOGGED IN USING FACEBOOK

        let facebookSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        facebookSheet.setInitialText("Share on Facebook")
        self.presentViewController(facebookSheet, animated: true, completion: nil)

    } else {  // USER DID NOT USE FB TO LOG IN

        let 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)
    }

}

我得到的唯一结果是else和我的警报控制器弹出。我已验证我已使用Facebook登录该应用程序。我错过了什么?提前谢谢。

只是开玩笑,这段代码可以工作,只是不在模拟器中。有一次我插上电话,在那里试了试,效果很好。与定位服务、通知和消息UI非常相似;他们在实际的iPhone上工作,而不是在模拟器中