我最近使用社交框架在facebook和twitter上发布。 Twitter工作正常,即使Facebook工作,如果该设备没有在其中的Facebook应用程序。但是,如果它已安装,那么它会打开一些没有初始文本的其他窗口。有谁知道为什么会发生这种情况,这可以解决吗?
你可以使用SLComposeViewController共享文本,图像,链接,我希望它能为你工作。
let mySLComposerSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
mySLComposerSheet.setInitialText("Sharetext")
mySLComposerSheet.addURL(NSURL(string: "www.shareurl.com"))
mySLComposerSheet.addImage(UIImage(named:"image"))
mySLComposerSheet.completionHandler = {
(result:SLComposeViewControllerResult) in
mySLComposerSheet.dismissViewControllerAnimated(true, completion: { () -> Void in
if result == SLComposeViewControllerResult.Done {
print("success")
} else {
print("fail")
}
});
}
self.presentViewController(mySLComposerSheet, animated: true) { () -> Void in
}
swift3.0
let mySLComposerSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
mySLComposerSheet.setInitialText("Sharetext")
mySLComposerSheet.add(URL(string: "www.shareurl.com"))
mySLComposerSheet.add(UIImage(named: "image"))
mySLComposerSheet.completionHandler = {
(result:SLComposeViewControllerResult) in
mySLComposerSheet.dismiss(animated: true, completion: { () -> Void in
if result == SLComposeViewControllerResult.done {
print("success")
} else {
print("fail")
}
});
}
self.present(mySLComposerSheet, animated: true) { () -> Void in
}