Created
May 20, 2019 10:06
-
-
Save hansemannn/e92fe190325ea42809ee0116482de0b2 to your computer and use it in GitHub Desktop.
Titanium Deep Linking Manager (iOS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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