Deep linking
What is deep linking?
Deep linking does this by specifying a custom URL scheme (iOS Universal Links) or an intent URL (on Android devices) that opens your app if it’s already installed. Deep links can also be set to direct users to specific events or pages, which could tie into campaigns that you may want to run.
IoPay supports deep link below to open your pages in ioPay dapp browser :
iopay://io.iotex.iopay/open?action=web&url={{URL}}
How to open your dapp in ioPay with deep link?
export const helper = {
isPc() {
const userAgentInfo = global?.navigator?.userAgent;
const Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
let flag = true;
for (let v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
},
// check the dapp is in a mobile system browser
checkEnv() {
const isPc = this.isPc()
const isBrower = typeof window === 'undefined' ? false : true
const isIopayMobile = window?.navigator?.userAgent && (window?.navigator?.userAgent.includes('IoPayAndroid') || window?.navigator?.userAgent.includes('IoPayiOs'))
console.log('isBrower', isBrower, 'isIopayMobile' , isIopayMobile)
if (!isPc) {
if(isBrower && isIopayMobile) {
return true
} else if (isBrower && !isIopayMobile) {
this.openDeepLink()
return false
}
}
return true;
},
//open the dapp with ioPay deep linking
openDeepLink() {
const a = document.createElement("a");
const tagId = "startIoPay";
a.setAttribute("href", `iopay://io.iotex.iopay/open?action=web&url=${window.location.href}`);
a.setAttribute("id", tagId);
if (document.getElementById(tagId)) {
// @ts-ignore
document.body.removeChild(document.getElementById(tagId));
}
document.body.appendChild(a);
a.click();
setTimeout(() => {
window.location.href = 'https://iopay.me/'
}, 4000)
}
}
Last updated