share on facebook messenger - ios

For an app I'm working on I'm integrating different social services the user can select to share the content created using the app.
What I'm trying to understand is if the facebook-messenger app expose an URL scheme that can be used to perform some action (basically texting one of his/her friend), or if there is a specific UTI that can be used in conjunction with the UIDocumentInteractionController.
Thanks in advance for any help / hint / suggestion

You cannot compose message but you can send a link, photo or video via messenger.
Facebook provides API for that.
Import FBSDKShareKit
#import <FBSDKShareKit.h>
Create content and share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.url.com"];
content.contentTitle = #"My link!";
content.contentDescription = #"Check out my link!";
[FBSDKMessageDialog showWithContent:content delegate:self];
You also need to conform your controller to the FBSDKSharingDelegate
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}
Available contents are:
FBSDKShareLinkContent
FBSDKSharePhotoContent
FBSDKShareVideoContent

Facebook Messenger URL scheme on iOS is fb-messenger://, I don't know if it's possible to open a composer that will let you choose contacts or pre fill it with a message.
You can open a conversation if you know the Facebook user ID: fb-messenger://user-thread/[facebook-user-id]

Related

Cannot Open Messenger from iOS using Facebook 4.37.0

I am trying to open Facebook Messenger to send a message from my iOS app. I am currently running FaceBook SDK version 4.37.0. According to iOS - Sharing, this should be possible. It says
People can also share content from your app to Facebook Messenger with Messenger Expression Platform or from Sharing's Message Dialog in iOS SDK.
If you click on the link for Message Dialog, it provides you with the following example:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:myFacebookURL];
content.quote = #"My message";
[FBSDKMessageDialog showWithContent:content delegate:self];
I have implemented this as well as the FBSDKSharingDelegate delegate methods of:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"complete");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"Sharer Error");
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"Cancelled");
}
The delegate methods never get called. What I would expect is that a Facebook Messenger dialog would open allowing me to select a friend to message. But nothing opens. And there are no errors being logged.
I do know that facebook is receiving something because I get the following:
FBSDKLog: param {
"advertiser_id" = "xxxxxxxxx";
"advertiser_tracking_enabled" = 1;
"anon_id" = "xxxxxxxx";
"application_
tracking_enabled" = 1;
"custom_events" = "[{\"_eventName\":\"fb_mobile_content_view\",\"_logTime\":1541721304,\"fb_description\":\"MY FEATURE Sent\",\"_ui\":\"no_ui\"},{\"_ui\":\"no_ui\",\"_eventName\":\"fb_messenger_dialog_share_show\",\"_logTime\":1541721310,\"_implicitlyLogged\":\"1\",\"fb_dialog_share_content_type\":\"Status\"}]";
event = "CUSTOM_APP_EVENTS";
extinfo = "[\"i2\",\"com.myApp\",\"1\",\"8.3.6\",\"12.0.1\",\"iPhone10,6\",\"en_US\",\"CST\",\"AT&T\",375,812,\"3.00\",6,60,8,\"America\\/Chicago\"]";
"url_schemes" = "[\"myappID\",\"myscheme1\",\"myscheme2\",\"myscheme3\"]";
}
Any help or pointers would be appreciated.
FBSDKMessageDialog.show(with: FBSDKShareLinkContent(), delegate: nil)
I have the same issue but experimentally I only pass FBSDKShareLinkContent() as a content param and messenger app start
You should also add fb-messenger-share-api key in Info.plist under LSApplicationQueriesSchemes

iOS Facebook issue share link dialog, how to know User share success?

When I choose X or Post success, FBSDK (version 4.26.0) always callback the same method (Device don't install Facebook app)
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
results is empty
How can I know it's user shared success or cancel it?
Please help me!
I'm using this method
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = URL;
[FBSDKShareDialog showFromViewController:viewController withContent:content delegate:self];
I received the callback below:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"completed");
}
but the problem is when I choose X (To close the sharing interface) or Post (To share the content successfully), FBSDK (version 4.26.0) always callback same method didCompleteWithResults with results = empty
Noted: device doesn't install Facebook App

SLComposeViewController post both image and url ios9

What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9
UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addURL:[NSURL URLWithString:str]];
[fbSheet addImage:tableViewScreenshot];
The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device.
And this one is when the Facebook app is not installed on the device
And this is my code:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addURL:[NSURL URLWithString:#"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"icon_circle"]];
[controller setInitialText:#"Bhavuk you're great!"];
[self presentViewController:controller animated:YES completion:nil];
So If you want to share everything, better use FB SDK.
So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.
Unfortunately, the problem remains even on iOS 10. An easy workaround is simply drop the URL, for example:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addImage:tableViewScreenshot];
It's not a direct answer to the OP but in case of what you only care is showing text and image while sharing something, here is a possible solution:
If the image and the text that you want to show within your SlComposeView is the same as the information that exist within the web site that you are going to share; you don't need to do anything special at the iOS side at all.
If you are the one who also created the web page that you're sharing URL of, should you have proper Open Graph META Tags at the page, SLComposeView of type Facebook will show image and text which were set at the webpage within your app automagically.
For some information about Facebook Open Graph Markup; see https://developers.facebook.com/docs/sharing/webmasters/#markup
I have had facebook sharing working fine in my ios app when fb not install. and i have installed fb to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NIDINFO(#"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(#"Facebook sharing getting publish_actions permission failed: %#", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: #{
#"og:type": #"article",
#"og:title": #"Bloc",
#"og:description": message,
#"og:url": #"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"mynamespace:Share" object:object key:#"article"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(#"Facebook sharing content failed: %#", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(#"Facebook sharing completed: %#", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(#"Facebook sharing failed: %#", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(#"Facebook sharing cancelled.");
}

FBSDKShareDialog iOS 9 without Fb app

I want to allow users without FB app to share open graph - to call share dialog. (With FB app, all working perfect). Is that possible on iOS9? Here is the code (i made content and all):
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
shareDialog.delegate = self;
[shareDialog show];
if (![shareDialog canShow]) {
// update the app UI accordingly
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
// check the error for explanation of invalid content
}
And here what i get when i try to share without FB app (app is not crashing, nothing happen):
-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
Before sharing in the app, user can login successfully in fb with Safari..
Thanks.

Facebook Messenger Compose Predefined Message

I am using fb-messenger://compose to open Facebook Messenger Composer, but I can't manage to put predefined message into the composer.
Does somebody know the parameters?
You should send content via messenger using FBSDKShareKit.
Import FBSDKShareKit
#import <FBSDKShareKit.h>
Create content and share
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.url.com"];
content.contentTitle = #"My link!";
content.contentDescription = #"Check out my link!";
[FBSDKMessageDialog showWithContent:content delegate:self];
You also need to conform your controller to the FBSDKSharingDelegate
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}
Available contents are:
FBSDKShareLinkContent
FBSDKSharePhotoContent
FBSDKShareVideoContent

Resources