我正在尝试在iOS应用中使用SLComposeViewController将帖子分享到Facebook。但是,如果我取消发布,完成处理程序会返回“Done”而不是“Cancelled”的结果。当我点击发布时,它会关闭并冻结应用程序而不返回任何结果。如果设备上没有安装Facebook应用程序,则此代码可以正常工作。
这是我用于Facebook部分的代码:
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
var facebookVC: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookVC.completionHandler = {
(result: SLComposeViewControllerResult) -> Void in
println("result: \(result.rawValue)")
switch(result) {
case SLComposeViewControllerResult.Cancelled:
println("Facebook CANCELLED")
break;
case SLComposeViewControllerResult.Done:
println("Facebook DONE")
self.facebookButton.selected = true
self.facebookButton.userInteractionEnabled = false
break;
default:
break;
}
}
self.presentViewController(facebookVC, animated: true, completion: nil)
} else {
var alert: UIAlertView!
alert = UIAlertView(title: "No Facebook Account", message: "There are no Facebook account configured. You can add or create a Facebook account in Settings", delegate: self, cancelButtonTitle: "OK")
alert.show()
}