简体   繁体   中英

Swift Facebook Invite Friends

I'm trying to create Facebook Invite button in my app. Whenever a user clicks "Invite friends" new windows opens and then closes after 2-3 secs with this error in console:

"Error: Optional(Error Domain=com.facebook.sdk.core Code=9 \"(null)\")"

This is how I'm creating invite window:

func inviteFacebookFriends(){
    let dialog = FBSDKAppInviteDialog()
    let content:FBSDKAppInviteContent = FBSDKAppInviteContent()
    content.appLinkURL = URL(string: "http://example.com/")
    content.appInvitePreviewImageURL = URL(string: "http://example.com/image.jpg")
    dialog.content = content
    dialog.delegate = self
    do {
        try dialog.validate()
    }
    catch {
        print(error)
    }

    dialog.show()
}

All delegates are in the class

func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [AnyHashable : Any]!) {
    debugPrint("Success: " + String(describing: results))
}
func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: Error!) {
    debugPrint("Error: " + String(describing: error))
}

In my .plist I have FacebookAppID and FacebookDisplayName . What am I doing wrong?

Make sure you have

[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

in your AppDelegate.

Facebook App delegate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM