proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.29k stars 218 forks source link

How to handle callback urls in the app from InAppBrowser. #439

Open mksmanish opened 9 months ago

mksmanish commented 9 months ago
```
      const openLink = async (url) => {
try {
  if (await InAppBrowser.isAvailable()) {
    InAppBrowser.open(url, {
      // Configure your InAppBrowser options here
      // ...

    })
      .then((result) => {
        console.log("printing result", result);
        if (result.type === "loadstop") {
          // The "loadstop" event occurs when the page/resource finishes loading.
          const callbackUrl = result.url;
          console.log(`Received callback URL: ${callbackUrl}`);

          // Check if this is the callback URL you're expecting
          if (callbackUrl.startsWith("your-callback-url")) {
            // Handle the callback URL here
            // You can parse the URL and extract data as needed
          }
        }
      })
      .catch((error) => {
        console.error("InAppBrowser open error:", error);
      });
  } else {
    // Fallback to Linking if InAppBrowser is not available
    Linking.openURL(url);
  }
} catch (error) {
  console.error("An error occurred:", error);
}

};

Noitham commented 9 months ago

It seems callbacks are not supported with the default InAppBrowser.open, only with openAuth.