-
Notifications
You must be signed in to change notification settings - Fork 5
How to use "deeplink" to land user to a particular app page?
This page describes one of the approaches of handling deep links in your app. It uses references to Example app, to configure it for your applicationCode use How to start Example app.
First you will need to identify the schema for your deep link, usually it is reverse DNS notation:
com.infobip.mobilemessaging://deeplink/
. And also define screens that you want to open as part of deep link such as testDeeplinkingScreen
, testDeeplinkingScreen2
. And then it will be possible to send deep link over push message and to handle notificationTapped
event.
To send message with deeplink
parameter you can use Portal or HTTP API, ask your account manager in case of further questions. For our example deep link parameter will be following com.infobip.mobilemessaging://deeplink/testDeeplinkingScreen/testDeeplinkingScreen2
In the Example app 2 simple screens for deeplink testing created, you can check them:
testDeeplinkingScreen.js, testDeeplinkingScreen2.js
These screens are added to the NavigationStack
in App.js
render() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen}/>
<Stack.Screen name={'TestDeeplinkingScreen'} component={TestDeeplinkingScreen}/>
<Stack.Screen name={'TestDeeplinkingScreen2'} component={TestDeeplinkingScreen2}/>
</Stack.Navigator>
</NavigationContainer>
);
}
In the Example app handleDeeplinkEvent
method is implemented in homeScreen.js.
For parsing url properly react-native-url-polyfill
dependency was added.
handleDeeplinkEvent = (deeplinkUrl) => {
//taking not empty path segments from Url
let pathSegments = new URL(deeplinkUrl).pathname.split('/').filter(Boolean);
for (let pathSegment of pathSegments) {
//opening of the concrete screen, using react native Navigation
this.props.navigation.navigate(pathSegment);
}
};
mobileMessaging.register("notificationTapped", (eventData) => {
if (!eventData[0].deeplink) {
return;
}
this.handleDeeplinkEvent(eventData[0].deeplink);
});
Don't forget to unregister from notificationTapped
event on componentWillUnmount()
method.
mobileMessaging.unregister("notificationTapped", this.handleNotificationTappedEvent);
React Native's Linking library is used, check its documentation for additional information.
Register iOS application for custom URL scheme as described here
In provided example iOS application is registered for com.infobip.mobilemessaging
scheme. Check project by opening Example.xcworkspace in Xcode, other changes are in AppDelegate.mm
Register Android application for custom URL scheme as described here
In provided example Android application is registered for com.infobip.mobilemessaging
scheme. Check it by opening AndroidManifest.xml
To handle deeplink if application is already opened call handleDeeplinkEvent
as callback for Linking.addEventListener('url', callback)
Linking.addEventListener('url', (initialUrlDict) => {
this.handleDeeplinkEvent(initialUrlDict.url);
});
To handle deeplink if application isn't opened use Linking.getInitialURL()
method.
Linking.getInitialURL().then((initialUrl) => {
if (!initialUrl) {
return;
}
this.handleDeeplinkEvent(initialUrl);
}).catch(error => {
console.log('Initial URL is not provided');
})
Full source code can be found in example application. It can be tested for Android by calling from command line following code:
adb shell am start -a android.intent.action.VIEW -d "com.infobip.mobilemessaging://deeplink/TestDeeplinkingScreen/TestDeeplinkingScreen2" com.example
for iOS just open link com.infobip.mobilemessaging://deeplink/TestDeeplinkingScreen/TestDeeplinkingScreen2
in a browser.
If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
- Privacy settings
- In‐app chat
- WebRTC Calls and UI
- Migration guides