Skip to content

Instantly share code, notes, and snippets.

@brentonhouse
Forked from hansemannn/deep-linking-manager.js
Created January 29, 2020 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentonhouse/7288e0bdfea85475a1c3bdd002c420db to your computer and use it in GitHub Desktop.
Save brentonhouse/7288e0bdfea85475a1c3bdd002c420db to your computer and use it in GitHub Desktop.
Titanium Deep Linking Manager (iOS)
export default class DeepLinkingManager {
constructor () {
this.handledLinks = {};
this.activityType = 'io.lambus.app.universalLink';
const activity = Ti.App.iOS.createUserActivity({
activityType: this.activityType
});
activity.becomeCurrent();
Ti.App.iOS.addEventListener('continueactivity', event => {
if (event.activityType === 'NSUserActivityTypeBrowsingWeb') {
try {
const matchedLink = Object.keys(this.handledLinks).find(link => {
return event.webpageURL.indexOf(link) !== -1;
});
if (!matchedLink) {
Ti.API.error(`Cannot handle link = ${link}!`);
}
this.handledLinks[matchedLink](event.webpageURL);
} catch (err) {
console.error(err);
}
}
});
console.log('Listening for deep-links …');
}
onLinkHandled(link, callback) {
if (this.handledLinks[link]) {
Ti.API.error(`Link = ${link} already handled!`);
return;
}
this.handledLinks[link] = callback;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment