Ich versuche, Facebooks Open Graph Stories-Funktion in Swift zu verwenden, um bei jeder Überprüfung eines Standorts auf der Timeline eines Benutzers zu posten. Aber jeder Share-Dialog öffnet sich, ich bekomme immer this Fehler.Swift: Versuchen, Facebook zu verwenden Öffnen Sie Graph Stories
Ich folgte den Facebook Docs beim Erstellen eines Objekts, und dann eine Aktion, und dann schließlich Inhalt. Aber es scheint nicht zu funktionieren.
Unten ist mein Code:
class rateViewController: UIViewController, FBSDKSharingDelegate{
@IBOutlet weak var card: UIView!
@IBOutlet weak var cardBackground: UIView!
// VARIABLES
// CREATE THE OPENGRAPH OBJECT
var openGraphTest = FBSDKShareOpenGraphObject.init(properties: [
"place:location:latitude": "51.043553",
"place:location:longitude":"-114.078141",
"og:type" : "place",
"og:title" : "Rating"
])
// CREATE AN ACTION
var action = FBSDKShareOpenGraphAction.init()
// CREATE CONTENT
let content = FBSDKShareOpenGraphContent.init()
override func viewDidLoad() {
super.viewDidLoad()
action.actionType = "og.likes"
action.setObject(openGraphTest, forKey: "place")
content.action = action
content.previewPropertyName = "place"
// Do any additional setup after loading the view.
}
@IBAction func panCard(_ sender: UIPanGestureRecognizer) {
let card = sender.view! // Represents card UIView
let point = sender.translation(in: view) // How far you moved your finger, when touching view and dragging
card.center = CGPoint(x:(view.center.x + point.x), y: (view.center.y + point.y))
// RECENTERING THE CARD AFTER USER REMOVES FINGER FROM SCREEN
if(sender.state == UIGestureRecognizerState.ended){
if(card.center.x < 75){
// MOVE CARD TO THE LEFT SIDE OF SCREEN
UIView.animate(withDuration: 0.3, animations: {
card.center = CGPoint(x: self.cardBackground.center.x - 300, y: self.cardBackground.center.y + 75)
card.alpha = 0
})
return
}
else if(card.center.x > (view.frame.width - 75)){
// MOVE CARD TO THE RIGHT SIDE OF SCREEN
UIView.animate(withDuration: 0.3, animations: {
card.center = CGPoint(x: self.cardBackground.center.x + 300, y: self.cardBackground.center.y + 75)
card.alpha = 0
})
// SHOW THE FACEBOOK SHARE DIALOG
try FBSDKShareDialog.show(from: self, with: content, delegate: self)
return
}
UIView.animate(withDuration: 0.2) {
card.center = self.cardBackground.center
}
}
}
@IBAction func likeButton(_ sender: UIButton) {
// MOVE CARD TO THE RIGHT SIDE OF SCREEN
UIView.animate(withDuration: 0.3, animations: {
self.card.center = CGPoint(x: self.cardBackground.center.x + 300, y: self.cardBackground.center.y + 75)
self.card.alpha = 0
})
}
@IBAction func dislikeButton(_ sender: UIButton) {
// MOVE CARD TO LEFT SIDE OF SCREEN
UIView.animate(withDuration: 0.3, animations: {
self.card.center = CGPoint(x: self.cardBackground.center.x - 300, y: self.cardBackground.center.y + 75)
self.card.alpha = 0
})
}
// FACEBOOK SHARING DELEGATE
/**
Sent to the delegate when the share completes without error or cancellation.
- Parameter sharer: The FBSDKSharing that completed.
- Parameter results: The results from the sharer. This may be nil or empty.
*/
public func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!){
}
/**
Sent to the delegate when the sharer encounters an error.
- Parameter sharer: The FBSDKSharing that completed.
- Parameter error: The error.
*/
public func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!){
print("Error: ", error)
}
/**
Sent to the delegate when the sharer is cancelled.
- Parameter sharer: The FBSDKSharing that completed.
*/
public func sharerDidCancel(_ sharer: FBSDKSharing!){
self.dismiss(animated: true, completion: nil)
}
}