diff --git a/ios/TrustlyReactNativeExample/AppDelegate.mm b/ios/TrustlyReactNativeExample/AppDelegate.mm index 589d8a0..252fac5 100644 --- a/ios/TrustlyReactNativeExample/AppDelegate.mm +++ b/ios/TrustlyReactNativeExample/AppDelegate.mm @@ -2,6 +2,9 @@ #import +#import + + @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @@ -14,6 +17,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return [super application:application didFinishLaunchingWithOptions:launchOptions]; } + +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + options:(NSDictionary *)options { + return [RCTLinkingManager application:application openURL:url options:options]; +} + - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG diff --git a/src/App.tsx b/src/App.tsx index 87fe029..34f1cc4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -44,7 +44,9 @@ const ResultScreen = ({ title, returnParameters, onBackToWidget }) => ( ); export default class App extends Component { - trustlyWebView = null; + + trustlyWebView: WebView | null = null; + deepLinkEventListener: any = null; // Initialize payment data establishData: EstablishData = { @@ -75,10 +77,19 @@ export default class App extends Component { returnParameters: '', }; - constructor(props) { - super(props); + componentDidMount() { + this.deepLinkEventListener = Linking.addEventListener('url', this.handleDeepLink); + } + + componentWillUnmount() { + this.deepLinkEventListener.remove() } + // Handle the deep link URL here + handleDeepLink = () => { + InAppBrowser.closeAuth(); // Close the InAppBrowser when a deep link is detected + }; + // Open the provided URL in InAppBrowser or default browser if not available async openLink(url: string) { try { @@ -155,9 +166,7 @@ export default class App extends Component { // Handle the OAuth result handleOAuthResult = (result: any) => { - if (result.type === 'success') { - this.trustlyWebView.injectJavaScript('window.Trustly.proceedToChooseAccount();'); // Proceed with the transaction - } + this.trustlyWebView.injectJavaScript('window.Trustly.proceedToChooseAccount();'); // Proceed with the transaction }; // Update the amount when the user inputs a new value