首页 > 解决方案 > 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.

标签: react-nativeexporeact-native-linkingbankid

解决方案


您可以使用 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)
    };

推荐阅读