-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling deep links on iOS #421
Comments
Have you tried following the manual setup instructions here: https://developers.intercom.com/installing-intercom/docs/ios-push-notifications Namely setting the and then seeing if the If that is called you should be able to grab the url from After that you can either call
or just pass it to your deep link handler directly |
Also having the same issue on iOS, I have deep links working everywhere else just not from Intercom Notifications, feels like library issue when it works on android but not on iOS. @johnryan you might be on to something but could you detail it a little more? 🤔 How would you extract the deep link URL from userInfo and pass it to for example |
@du5rte You probably need to be on the latest Intercom version - but what I was suggesting was to just get the value you want out of the userInfo dictionary - you'd have to take a look at that object and grab whatever key you want |
Edit 2: Check new solution bellow 👇 |
Update! Found a more elegant solution and that works when the app is closed. Checklist, make sure you've done these steps before:
The ProblemThe core issue of Intercom not handling deep links for me was that The SolutionHandle intercom notifications manually, intercept notifications with deep links inside it and store it to open later when the app is ready. Read more on the original solution Steps:
<key>IntercomAutoIntegratePushNotifications</key>
<string>NO</string>
// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
// Required for handleIntercomPushNotification function bellow
NSDictionary *userInfo = response.notification.request.content.userInfo;
// Required to handle Intercom push notifications manually
if ([Intercom isIntercomPushNotification:userInfo]) {
[Intercom handleIntercomPushNotification:userInfo];
}
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
}
// Must be outside of any component LifeCycle (such as `componentDidMount`).
PushNotification.configure({
// ...
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: function (notification) {
console.log('[Notification]', notification)
// If notification is interactive
if (notification.userInteraction) {
const url = (notification.data as any)?.uri
if (url) {
/**
* When handling a notification with a deep link
*
* if the app is initialized just open url
* else save it to AsyncStorage and handle it later
*/
if (global.initialized === true) {
Linking.openURL(url)
} else {
AsyncStorage.setItem('initialURL', url)
.then(() => {
console.log('[Notification/AsyncStorage] initial url', url)
})
.catch(console.error)
}
}
}
// (required) Called when a remote is received or opened, or local notification is opened
notification.finish(PushNotificationIOS.FetchResult.NoData)
},
// ...
})
await authenticate()
// set initialized, important to
global.initialized = true
// check if there was a initialURL stored
const initialURL = await AsyncStorage.getItem('initialURL')
// open and delete it
if (initialURL) {
await Linking.openURL(initialURL)
await AsyncStorage.removeItem('initialURL')
}
const linking = {
// ...
// Custom function to get the URL which was used to open the app
async getInitialURL() {
console.log('[Navigation/Linking] Getting initial url')
// Check if app was opened from a deep link
const url = await Linking.getInitialURL()
if (url != null) {
console.log('[Navigation/Linking] Has initial url', url)
return url
}
// Check for additional initial deep link in AsyncStorage stored by notifications
const initialURL = await AsyncStorage.getItem('initialURL')
if (initialURL != null) {
console.log('[Navigation/AsyncStorage] Has initial url', initialURL)
await AsyncStorage.removeItem('initialURL')
return initialURL
}
},
// ...
}
function App() {
return (
<Auth>
<NavigationContainer linking={linking} />
...
</NavigationContainer>
</Auth>
)
} Important to do the authentication before the routing
function Auth(props) {
async function init() {
try {
await authenticate()
global.initialized = true
} catch (error) {
console.error(error)
}
}
return loading ? (
<LoadingIndicator />
) : (
props.children
)}
} For TypeScript users here's how you fix the
declare module '*.png'
declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV?: 'development' | 'test' | 'production'
}
interface Global {
initialized: boolean
}
}
}
// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.
export {} |
@du5rte @hanniedong |
I'm using branch.io to handle deep linking and have it working with another push notification platform (One Signal).
I'm able to receive push notifications (using intercom and this library) on both iOS and Android. The only difference is the handling of the deep link. Deep links work in Android, so when I tap on the push notification, it takes me to the correct screen in the app. For iOS, tapping the push notification only opens the app and doesn't carry over the deep link.
Has anyone figured out how to handle deep links coming from Intercom push notifications?
The text was updated successfully, but these errors were encountered: