例如,我知道我可以深度链接 map ,我用过它并且效果很好。但是 FB Messenger 怎么样?我有一个按钮,当用户单击时我希望它打开 Messenger 并与某人对话。我该怎么做?我尝试直接链接,但它不起作用。
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}
还是不行。
顺便说一句,有没有办法询问用户他想用哪个应用程序打开?对于 map ,当我单击按钮时,它会在 iOS 上的 Apple Maps 上打开,但我希望它询问要打开哪个应用程序,因为我不使用 Apple Maps。
最佳答案
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>
安卓
To support deep linking on Android, refer http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents
关于javascript - React-Native 将应用链接到 Facebook Messenger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548911/