1

I’m Implementing deep link in react native app to click on View in app A to open app B. Before calling URL directly from another app I wanted to test it if it is working or not,

So for android it worked. I just set the launch option to URL and it showed the value of URL in console.

But in iPhone if I write the URL(testlink://) in safari browser it shows “safari cannot open the page because address is invalid”.

Steps I followed to setup deeplinking:

  1. Added following code in AppDelgate.m

    #import <React/RCTLinkingManager.h>
    
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
      return [RCTLinkingManager application:application openURL:url
                          sourceApplication:sourceApplication annotation:annotation];
    }
    
    - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
     restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
    {
     return [RCTLinkingManager application:application
                      continueUserActivity:userActivity
                        restorationHandler:restorationHandler];
    }

  1. Added a key in info.plist in XCode.

    URLTypes -> Item 0 -> URL identifier(VALUE: testlink)

  2. Adding the following code in Home page of the App.

   

 componentDidMount() {
      Linking.addEventListener('url', this._handleOpenURL);
    },
    componentWillUnmount() {
      Linking.removeEventListener('url', this._handleOpenURL);
    },
    _handleOpenURL(event) {
      console.log(event.url);
    }

1 Answer 1

7

Have you added testlink:// as a URL type in XCode?

For the purpose of this example, my Bundle Identifier is: org.reactjs.native.example.MyApp

  1. Click on your project in Xcode, and click on the Info tab
  2. Scroll down to URL Types
  3. Click the + button
  4. Add the Identifier: org.reactjs.native.example.MyApp.linking
  5. Add URL Schemes: testlink
  6. Clean & Build
  7. Open Safari and type in testlink:// - it should open your app.
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you it worked but now I'm facing a weird issue if the app is already open it shows the black screen. Any suggestions?
If the app is already open from URL then it shows the black screen on calling the URL again otherwise it works fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.