简体   繁体   中英

React-Native Link app to Facebook Messenger

I know I can deep link maps for example, I used it and it works fine. But how about FB Messenger? I have a button, that when user clicks I want it to open Messenger with a conversation with someone. How can I do it? I tried directly linking but it doesn't work.

  openMessenger() {
    Linking.canOpenURL('https://www.messenger.com/t/name').then(supported => {
        if (supported) {
            Linking.openURL('https://www.messenger.com/t/name');
        } else {
            console.log('erro');
        }
    }).catch(err => console.error('An error occurred', err));
  }

also tried fb-messenger://user-thread/{user-id} and still didn't work.

btw, is there any way to ask the user which app he wants to open with? In the case of the maps, when I click the button it opens on Apple Maps on iOS, but I want it to ask which app to open instead, as I don't use Apple Maps for example.

对于那些寻找答案的人来说,这个库对我有用https//github.com/fiber-god/react-native-app-link

Linking.canOpenURL('fb-messenger://').then(supported => {
    if (!supported) {
       console.log('Can\'t handle url: ' + url);
    } else {
       Linking.openURL("fb-messenger://user-thread/" + "facebook id");
    }
}).catch(err => console.log(err)));

iOS

As of iOS 9, your app needs to provide the LSApplicationQueriesSchemes key inside Info.plist or canOpenURL will always return false.

Set LSApplicationQueriesSchemes => Restart server

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-share-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
    <string>fb-messenger</string>
</array>

在此输入图像描述

Android

To support deep linking on Android, refer http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents

In case you are still wondering this is a straightforward way just to messenger to the existing react native application without any packages

Linking.openURL( http://m.me/<PAGE_NAME> )

Official Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM