iOS implementations use a custom URL scheme to launch the Facebook app and pass it content. In general, your sharing flow should:
You can pass the following content to the Facebook app:
Content | Key Name | Type | Description |
---|---|---|---|
Facebook app ID * |
|
| (Required) Your Facebook app ID. Add the ID to your app’s |
Background image asset * |
|
| Data for an image asset in a supported format (JPG, PNG). Recommended dimensions: device fullscreen or smaller. Recommended ratio: 9:16. |
Background video asset * |
|
| Data for video asset in a supported format (H.264, H.265, WebM). Videos can be 1080p and up to 20 seconds in duration. Under 50 MB recommended. |
Sticker asset * |
|
| Data for an image asset in a supported format (JPG, PNG). Recommended dimensions: 640x480. This image will be placed as a sticker over the background. |
Background layer top color |
|
| A hex string color value used in conjunction with the background layer bottom color value. If both values are the same, the background layer will be a solid color. If they differ, they will be used to generate a gradient instead. |
Background layer bottom color |
|
| A hex string color value used in conjunction with the background layer bottom color value. If both values are the same, the background layer will be a solid color. If they differ, they will be used to generate a gradient instead. |
* In addition to your app's FB app ID, you must pass the Facebook app a background asset (image or video), a sticker asset, or both.
You need to add Facebook's custom URL scheme to the allow list in order for your app use it. To do this, add facebook-stories://
to the LSApplicationQueriesSchemes
key in your app's Info.plist
.
This sample code shows how to pass the Facebook app a background layer image asset.
- (void)shareBackgroundImage { [self backgroundImage:UIImagePNGRepresentation([UIImage imageNamed:@"backgroundImage"]) appID:@"your-app-id"]]; } - (void)backgroundImage:(NSData *)backgroundImage appID:(NSString *)appID { // Verify app can open custom URL scheme, open if able NSURL *urlScheme = [NSURL URLWithString:@"facebook-stories://share"]; if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) { // Assign background image asset to pasteboard NSArray *pasteboardItems = @[@{@"com.facebook.sharedSticker.backgroundImage" : backgroundImage, @"com.facebook.sharedSticker.appID" : appID}]; NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]}; // This call is iOS 10+, can use 'setItems' depending on what versions you support [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions]; [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil]; } else { // Handle older app versions or app not installed case } }
This sample code shows how to pass the Facebook app a background layer video asset.
- (void)shareBackgroundVideo { NSURL *const backgroundVideoURL = [[NSBundle bundleForClass:[self class]]URLForResource:@"backgroundVideo" withExtension:@"mp4"]; NSData *const backgroundVideoData = [NSData dataWithContentsOfURL:backgroundVideoURL]; [self backgroundVideo: backgroundVideoData appID: @"your-app-id"]; } - (void)backgroundVideo:(NSData *)backgroundVideo appID:(NSString *)appID { NSURL *urlScheme = [NSURL URLWithString:@"facebook-stories://share"]; if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) { // Assign background video asset to pasteboard NSArray *pasteboardItems = @[@{@"com.facebook.sharedSticker.backgroundVideo" : backgroundVideo, @"com.facebook.sharedSticker.appID" : appID}]; NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]}; // This call is iOS 10+, can use 'setItems' depending on what versions you support [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions]; [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil]; } else { // Handle older app versions or app not installed case } }
This sample code shows how to pass the Facebook app a sticker layer image asset, and a set of background layer colors. Note that if you do not supply background layer colors, we will set the background layer color to #222222
.
- (void)shareStickerImage { [self stickerImage:UIImagePNGRepresentation([UIImage imageNamed:@"stickerImage"]) backgroundTopColor:@"#444444" backgroundBottomColor:@"#333333" appID:@"your-app-id"]; } - (void)stickerImage:(NSData *)stickerImage backgroundTopColor:(NSString *)backgroundTopColor backgroundBottomColor:(NSString *)backgroundBottomColor appID:(NSString *)appID { // Verify app can open custom URL scheme. If able, // assign assets to pasteboard, open scheme. NSURL *urlScheme = [NSURL URLWithString:@"facebook-stories://share"]; if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) { // Assign sticker image asset to pasteboard NSArray *pasteboardItems = @[@{@"com.facebook.sharedSticker.stickerImage" : stickerImage, @"com.facebook.sharedSticker.backgroundTopColor" : backgroundTopColor, @"com.facebook.sharedSticker.backgroundBottomColor" : backgroundBottomColor, @"com.facebook.sharedSticker.appID" : appID}]; NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]}; // This call is iOS 10+, can use 'setItems' depending on what versions you support [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions]; [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil]; } else { // Handle older app versions or app not installed case } }
This sample code shows how to pass the Facebook app a background layer image asset, and a sticker layer image asset.
- (void)shareBackgroundAndStickerImage { [self backgroundImage:UIImagePNGRepresentation([UIImage imageNamed:@"backgroundImage"]) stickerImage:UIImagePNGRepresentation([UIImage imageNamed:@"stickerImage"]) appID:@"your-app-id"]; } - (void)backgroundImage:(NSData *)backgroundImage stickerImage:(NSData *)stickerImage appID:(NSString *)appID { // Verify app can open custom URL scheme. If able, // assign assets to pasteboard, open scheme. NSURL *urlScheme = [NSURL URLWithString:@"facebook-stories://share"]; if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) { // Assign background and sticker image assets to pasteboard NSArray *pasteboardItems = @[@{@"com.facebook.sharedSticker.backgroundImage" : backgroundImage, @"com.facebook.sharedSticker.stickerImage" : stickerImage, @"com.facebook.sharedSticker.appID" : appID}]; NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]}; // This call is iOS 10+, can use 'setItems' depending on what versions you support [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions]; [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil]; } else { // Handle older app versions or app not installed case } }