Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2.0 code for Facebook Friend Invite

I've been looking for an equivalent Swift code sample for Facebook friend invite for iOS apps. But I can't find them.

I understand that there is the Objective-C version on Facebook page https://developers.facebook.com/docs/app-invites/ios. However, because I started off with Swift, I find it difficult to translate.

Could someone point me to a source? Thank you.

like image 877
LFS Avatar asked Aug 11 '15 14:08

LFS


1 Answers

the code working :

-In viewDidLoad :

let content = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "https://test/myapplink")
content.appInvitePreviewImageURL = NSURL(string: "https://test/myapplink")
// Old Way, now depreciated :
//FBSDKAppInviteDialog.showFromViewController(self, withContent: content, delegate: self)
//New way : 
        FBSDKAppInviteDialog.showFromViewController(self, withContent: content, delegate: self)
// Do any additional setup after loading the view.

-In your viewController to conform the protocol delegate:

extension InviteFriendsViewController: FBSDKAppInviteDialogDelegate{
    func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) {
        //TODO
    }
    func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) {
        //TODO
    }
}
like image 102
Benobab Avatar answered Oct 05 '22 09:10

Benobab