React-Native Link 应用到 Facebook Messenger

React-Native Link app to Facebook Messenger

例如,我知道我可以深入 link 地图,我用过它并且效果很好。但是 FB Messenger 怎么样?我有一个按钮,当用户单击时我希望它打开 Messenger 并与某人对话。我该怎么做?我直接 linking 尝试了,但它不起作用。

  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));
  }

也试过fb-messenger://user-thread/{user-id}但还是不行。

顺便说一句,有没有办法询问用户他想用哪个应用程序打开?对于地图,当我单击按钮时,它会在 iOS 上的 Apple 地图上打开,但我希望它询问打开哪个应用程序,因为我不使用 Apple 地图。

对于那些寻找答案的人,这个库对我有用: 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.

设置 LSApplicationQueriesSchemes => 重启服务器

<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