Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a url link be shared from iOS app via FB Messenger without presenting UIActivityViewController dialog and not needing Facebook SDK?

I am wondering if it is possible to share/send a url link and other media from iOS app via Facebook Messenger app without having to open UIActivityViewController's activity sheet first, which in addition shows a number of other apps which can handle the intended data and does not allow to exclude apps only UIActivityTypes. I would like to present a FB Messenger dialog with pre-filled url link immediately after a button tap, so no dialog with multiple other apps.

Facebook documentation suggests we should use FB SDK in such cases: https://developers.facebook.com/docs/sharing/ios#message. But what is beyond me is that iOS seems to have a "native access" to the Messenger app (and other apps), but there is no good API which could facilitate some UI customisation.

Any idea if there is a way to directly open FB Messenger with pre-filled message without needing to present UIActivityViewController's activity sheet or installing FB SDK?

EDIT: Let me clarify, I would like to share a url link or other media, it is not necessary that the message is pre-filled with text.

like image 484
Au Ris Avatar asked Dec 01 '25 14:12

Au Ris


1 Answers

You can share a link via messenger in this way

let urlStr = String(format: "fb-messenger://share/?link=%@", sharelink!)
let url  = NSURL(string: urlStr)

if UIApplication.shared.canOpenURL(url! as URL) {
    UIApplication.shared.open(url! as URL, options: [:]) { (success) in
        if success {
            print("Messenger accessed successfully")
        } else {
            print("Error accessing Messenger")
        }
    }
} else {
    // show Install Messenger
}
like image 97
Chathz Avatar answered Dec 04 '25 06:12

Chathz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!