With the release of the Facebook SDK version 4.28.0, the Send Button is deprecated. It will be supported until February 5, 2018.

Send Button for iOS

The Send button lets people privately send photos, videos and links to their friends and contacts using the Facebook Messenger.

Sending via Messenger

The Send Button on mobile is a direct connection to the Facebook Messenger: After tapping the Send button, the person's device will fast-app-switch to the Messenger and pre-write a message draft containing your piece of content.

  1. Send Button: Will be displayed if Messenger is installed on the device. Person taps the Send Button, the Facebook Messenger will open via fast-app-switch.
  2. Send Dialog: The Messenger will show a message composer containing a previw of the piece of content.

You also have the option of building your own button that opens the Message dialog directly.

1. General iOS Setup

Complete the Getting Started Guide for Facebook iOS SDK before adding the send button. The guide will include:

  • Setting up a Facebook app.
  • Downloading and installing the Facebook iOS SDK.
  • Adding the Facebook iOS SDK to your project.
Facebook SDK for iOS - Getting Started

2. Add Frameworks

To use the Send button in your view you need to add the Frameworks FBSDKCoreKit and FBSDKShareKit. You can find both in the Facebook iOS directory (~/Documents/FacebookSDK).

// ViewController.m (example)
#import "ViewController.h" 
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

3. Add Send Button Code

For sending a link create a new instance of the object FBSDKShareLinkContent and set the property contentURL to the URL you want to send.

Next create a new Send button FBSDKSendButton instance and assign the FBSDKShareLinkContent object property shareContent as shown in the code example shown below.

// ViewController.m (example)
@implementation ViewController
- (void)viewDidLoad {
  [super viewDidLoad];

  
  FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
  content.contentURL = 
    [NSURL URLWithString:@"https://www.facebook.com/FacebookDevelopers"];
  
  FBSDKSendButton *button = [[FBSDKSendButton alloc] init];
  button.shareContent = content;  
  
  [self.view addSubview:button];
}
@end

4. Take care of "Non-Messenger" People

If the Messenger app is not installed, the Send button will be hidden. Be sure that your app layout is appropriate when this button is hidden. For example you could display the Share button instead (if you're not already using it).

To inspect whether the Send button can be displayed on the current device use the FBSDKSendButton property isHidden:

if (button.isHidden) {
  NSLog(@"Is hidden");
} else {
  [self.view addSubview:button];
}

Customizing Shared Content

Generally there are two options to customize your shared content:

  1. Adjust FBSDKShareLinkContent selectors
  2. Using FBSDKShareOpenGraphContent

FBSDKShareLinkContent Selectors

Below we show which properties you can use and which values they must have.

Selector Description Type

initWithContentURL

URL for the content being shared.

NSURL

contentTitle

The link title

NSString

contentDescription

The description of the link

NSString

imageURL

The network URL of an image

NSURL

The properties peopleIDs, placeID and ref are not available for the Send button. If you want to use these properties when sharing content, please use the Share button instead.

Usage example for FBSDKShareLinkContent Selectors

You can use the example posted below for testing the Send button in your app.

NSURL *contentURL = [[NSURL alloc] initWithString:
  @"http://en.wikipedia.org/wiki/Facebook"];

NSURL *imageURL = 
  [NSURL URLWithString:@"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];
  
_sendButton.shareContent = [[FBSDKShareLinkContent alloc]
  initWithContentURL: contentURL
  contentTitle: @"My Share Title"
  contentDescription: @"Lorem ipsum dolor sit amet."
  imageURL: imageURL
  peopleIDs: nil
  placeID: nil
  ref: nil
];

Display Example

For the message sender the result of the example code shown above will look somewhat like this:

Usage example for FBSDKShareOpenGraphContent

You can use the example posted below for testing the Send button in your app. Replace my_namespace, my_object and my_action with your app namespace and Open Graph object and actions.

NSString *previewPropertyName = @"my_namespace:my_object";

NSDictionary *objectProperties = @{
                                   @"og:type" : @"my_namespace:my_object",
                                   @"og:title": @"A title",
                                   @"og:description" : @"A description",
                                  };
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:objectProperties];

FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"my_namespace:my_action";
[action setObject:object forKey:previewPropertyName];

FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = previewPropertyName;

_sendButton.shareContent = content;