I want to open my game on the user´s device when the user visits my website and when the user has already installed my game on his mobile iOS/Android device. How can I open my game on the user´s device when the user visits my website?
I have tried it with this code on my website but it´s not working. My game is not opening on the iOS/Android device. Is it necessary to change something in my iOS project and Android project settings so that the game could get opened from my website?
<script>
(function() {
const CONFIG = {
appSchema: "nameofmyapp://app",
playStore: "https://play.google.com/store/apps/details?id=com.company.nameofmyapp“,
appStore: "https://apps.apple.com/app/id…“,
desktopFallback: "https://www.testwebsite.com"
};
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
let redirectUrl = CONFIG.desktopFallback;
let isMobile = false;
if (/android/i.test(userAgent)) {
redirectUrl = CONFIG.playStore;
isMobile = true;
} else if ((/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) || (/Macintosh/.test(userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 1 && !window.MSStream)) {
redirectUrl = CONFIG.appStore;
isMobile = true;
}
if (isMobile) {
window.location.href = CONFIG.appSchema;
setTimeout(function() {
window.location.href = redirectUrl;
}, 1500);
} else {
window.location.href = redirectUrl;
}
})();
</script>
Your website code alone cannot open the installed game. You first need to configure your app to support deep linking by registering a custom URL scheme on iOS and adding an intent filter on Android. Without these settings, the operating systems don't know that nameofmyapp://app belongs to your app, so nothing will happen. Also, many mobile browsers block apps from opening automatically when a page loads, so it's generally more reliable to launch the app after the user taps a button or link.