Home Ask Login Register

Developers Planet

Your answer is one click away!

Echizzle February 2016

Send a message to friend via Facebook SDK from iOS app

I heard that the chat API for Facebook was deprecated a couple years back but I'm wondering if by using the new messenger API, it's possible to send a message to a friend via Facebook. The user logs in with the login button and gets their info with a graph request and now I want to send a test message.

Here is the code to login (works)

class ViewController: UIViewController, FBSDKLoginButtonDelegate {

var currentUserIDString : String?

override func viewDidLoad() {

    let facebookLoginButton = FBSDKLoginButton()
    facebookLoginButton.delegate = self
    facebookLoginButton.center = self.view.center

    let button : UIButton = FBSDKMessengerShareButton.circularButtonWithStyle(FBSDKMessengerShareButtonStyle.Blue, width: 80)
    button.addTarget(self, action: "shareTest", forControlEvents: UIControlEvents.TouchUpInside)
    button.frame = CGRectMake(self.view.frame.size.width/2 - 40, 390, 80, 80)


// other methods


Login delegate, getting user's info (also works)

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {

    let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender, email"])

    graphRequest.startWithCompletionHandler { (connection, result, error) -> Void in

        if error != nil {

        else if let result = result {

            self.currentUserIDString = result["id"] as? String



Share method, having some trouble here... the code within the parameters dictionary and fields is probably incorrect, but the Facebook docs are pretty poor so it's hard to find good examples.

func shareTestGraphRequest() {

    if FBSDK        


Nomi February 2016

Using Facebook messenger SDK integration you can send message to your friends. But this just allows to send media like image, GIF, video and you can not send plain text through this SDK.

Post Status

Asked in February 2016
Viewed 1,687 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life