Daniel Weng
Daniel Weng

Reputation: 21

How to share only text on facebook messenger for iOS using url scheme

I want to share only text from my ios app to Facebook messenger.

Is it possible to send a message to the facebook messenger using url scheme?

ex: fb-messenger://post?text=hello
ex: fb-messenger://send?text=hello
ex: fb-messenger://messaging?text=hello

Objective-C code like

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb-messenger://"]]) {
    NSString *msgString = @"Hello World";
    NSString *urlString = [NSString stringWithFormat:@"fb-messenger://send?text=%@", msgString];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
} else {
    NSLog(@"Failed to open fb-messenger App ");
}

After searching for schemes I found that android is be solved. Here's link

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Your message");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");

try {
    startActivity(sendIntent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastHelper.show(this, "Please Install Facebook Messenger");
}

I searched all around google and stackoverflow but i didn't find any useful information.

Upvotes: 2

Views: 3462

Answers (1)

KBog
KBog

Reputation: 4650

This worked for me on iOS as of Feb 2018: fb-messenger://share?link=encodedLink

Please note that you can only send a link, you can't compose a message.

Upvotes: 1

Related Questions