Reputation: 632
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:
#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];
}
Added a key in info.plist in XCode.
URLTypes -> Item 0 -> URL identifier(VALUE: testlink)
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);
}
Upvotes: 1
Views: 2801
Reputation: 8844
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
Info
tabURL Types
org.reactjs.native.example.MyApp.linking
testlink
testlink://
- it should open your app.Upvotes: 7