Handle universal links

Prev Next

This method allows you to track universal links in your app when directed from your other Insider One platforms (e.g., Email, Web Push).

Requirements

To integrate universal links in your React Native project, you should first complete the integration for the Linking package.

Android

To handle universal links for the Android platform:

1. If necessary, review the URLs in AndroidManifest.XML.

2. Direct the URLs you captured to the handleUniversalLink method in the Insider plugin in JavaScript/TypeScript.

const handleOpenURL = (event) => {
    const url = event.url;

    console.log("[INSIDER][handleOpenURL] triggered. URL: " + url);
    
    // This method works only Android
    RNInsider.handleUniversalLink(url);
};

useEffect(() => {
    Linking.getInitialURL().then((initialUrl) => {
        if (initialUrl) {
            handleOpenURL({
                url: initialUrl
            });
        }
    });

    const urlEventListener = Linking.addEventListener('url', handleOpenURL);

    return () => {
        urlEventListener.remove();
    };
}, []);

iOS

To handle universal links for the iOS platform:

1. Add the Insider handleUniversalLink iOS method in the continueUserActivity method you added to the AppDelegate for Linking.

2. Add the Insider handleUrl iOS method in the openURL method to handle Insider's links.

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTLinkingManager.h>
#import <InsiderMobile/Insider.h>


@implementation AppDelegate

...
...
...


- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  // For Insider's links
  if ([[url scheme] containsString:@"insider"]) {
      [Insider handleUrl:url];
  }
  
  return [RCTLinkingManager application:application openURL:url options:options];
}


- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
 // For univesal links 
 [Insider handleUniversalLink:userActivity];

 return [RCTLinkingManager application:application
                  continueUserActivity:userActivity
                    restorationHandler:restorationHandler];
}

@end