react-native - React Native Linking Listener?
问题描述
Description:
Built an app, need to implement Swedish BankID. This means, when user presses a button, the Swedish BankID App opens, and when the user has signed in, the Swedish BankID App sends the user back to my app (which it does automatically), in which I need to retrieve data (if sign in was successful or not).
What needs to be accomplished:
Open Swedish BankID on the device from my app. Need to be able to receive a payload from Swedish BankID App in my app (Swedish BankID sends user automatically back to my app).
Current Code:
const url = `https://app.bankid.com/?${autoStartToken}`;
const supported = await Linking.canOpenURL(url);
if (supported) {
const answer = await Linking.openURL(url);
} else {
Alert.alert(`Don't know how to open this URL: ${url}`);
}
Currently, the Swedish BankID App opens correctly, my question is, is there any way to receive data from the other app? I know this is possible with Native Modules (running Objective-C etc), however I am using Expo Client and do not wish to eject.
I have yet to find anything that suggests that React-Native can listen to the other app.
解决方案
您可以使用 expo WebBrowser打开 url。对于身份验证,您将需要使用 WebBrowser.openAuthSessionAsync,如果您只想打开网页 WebBrowser.openBrowserAsync 示例:
...
import * as WebBrowser from 'expo-web-browser';
....
const handleLinkAsync = async () => {
let result = await WebBrowser.openBrowserAsync('https://google.com');
console.log(result)
};
推荐阅读
- sql - 获取参考表行的总和
- c++ - Adding a type to an existing template with out it being dropped c++17
- reactjs - (0 , _react.useEffect) 不是 Docker-compose 中 Storybook 的函数
- python - 在 Python 中以日志格式附加环境变量
- javascript - Javascript:当元素存在于数组中时,为什么 indexOf 函数返回 -1?
- python - 如何根据相邻列的值从数据框中的一列中读取值?
- c - I_n_test = I_N 在 for 循环中是什么意思?
- javascript - Dialogflow 实现:agent.add() 不返回对 webhook (twilio) 的响应,适用于 dialogflow 控制台和谷歌助手
- javascript - POST请求后如何实时刷新数据?
- jquery - Boostrap datepicker:如何设置日期和格式