I'm looking for an easy solution to post one link of my app e.g. on Facebook and it should automatically redirect to the right app store if the user accesses it with a mobile device. Otherwise the users should be redirected to my website.
If you want to roll your own and not use a third party, there's also a Javascript solution:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script>
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return "Windows Phone";
}
if (/android/i.test(userAgent)) {
return "Android";
}
// iOS detection from: https://mcmap.net/q/48374/-detect-if-device-is-ios
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return "iOS";
}
return "unknown";
}</script>
<script>
function DetectAndServe(){
let os = getMobileOperatingSystem();
if (os == "Android") {
window.location.href = "http://www.Androidexample.com";
} else if (os == "iOS") {
window.location.href = "http://www.IOSexample.com";
} else if (os == "Windows Phone") {
window.location.href = "http://www.WindowsPhoneexample.com";
} else {
window.location.href = "http://www.NowherLandexample.com";
}
}
</script>
</head>
<body onload="DetectAndServe()">
</body>
</html>
U mean something like this?
How to use onelink.to
onelink.to is the easy and fuss-free way to link to your app!
Just add the URLs to your app and we will determine which to use every time someone is using your onelink.to address.
You can use onelink.to free of charge, both for private and commercial use. We have no plans to change that.
And you can also add a fallback url to your website.
Hope this helps u out.
The objective is not to use third party´s
where do u read this? He wants an easy solution, so third party can be the solution he wants. –
Gymnosperm In PHP you can use something like:
<?php
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
//do something with this information
if( $iPod || $iPhone ){
//browser reported as an iPhone/iPod touch -- do something here
$string = "Location: <<your itunes app link>>";
header($string);
die();
}else if($iPad){
//browser reported as an iPad -- do something here
$string = "Location: <<your itunes app link>>";
header($string);
die();
}else if($Android){
//browser reported as an Android device -- do something here
$string = "Location: <<Google Play Link>>";
header($string);
die();
}else if($webOS){
//browser reported as a webOS device -- do something here
$string = "Location: <<Your Page link>>";
header($string);
die();
}else{
//browser reported as PC -- do something here
$string = "Location: <<Your Page link>>";
header($string);
die();
}
?>
You can use links for iTunes or Android, respectively:
itms-apps://itunes.apple.com/app/<<App ID>>
market://details?id=<<Package id>>
I don´t remember the source, but at least it works for me for sharing in other apps like Whatsapp, but unfortunately is not working on Facebook.
The problem in Facebook is that they use the metadata of the final link on the path of redirections, and the link points to GooglePlay store.
We were looking for a solution to direct users to the proper App Store, plus carry along extra metadata, so when the app is launched after App Store install, it would know where the user came from and launch a specific activity.
So, if any others like me hits this Stack Overflow article, a hint for obtaining both the OP's requirements, plus the extra benefits of carrying along extra metadata (and track all the conversions) is to look at Firebase Dynamic Links: https://firebase.google.com/docs/dynamic-links
You can create a short link for iTunes and Google Playstore at once with http://toSto.re.
Just select a name and the enter the different app store urls you get a link like toSto.re/facebook which directs automatically to the right url depending on the user agent and even supports Google Analytics itegration for some stats.
Plain javascript version:
<script>
window.addEventListener('DOMContentLoaded', (event) => {
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('android') > -1) {
window.location.href = 'https://play.google.com/store/apps/details?id=de.winterworks.ultimate_puzzle.winterworksGmbH.game';
} else if (userAgent.indexOf('iphone') > -1 || userAgent.indexOf('ipod') > -1 || userAgent.indexOf('ipad') > -1) {
window.location.href = 'https://apps.apple.com/us/app/puzzles-for-toddlers-kids/id1463362222';
}
});
</script>
You can create that functionality by Backend.Just create one PHP script or what ever language your backend is using.Here I am asuming PHP.
Just Create one php script that will determine that you are using iphone or android or web.check this link for php script Mobile or desktop browser detection and redirect to respective web page
And redirect it to respective Url.Like You can use a url of site with php file https://www.dawawas.com/detect_mobile.php
a user will share this url and when another user will tap on above link then php script will determine whether it ios or android or web and repective link will open automatically via redirection
I have implemented this in our ios app.
You can use simple javascript code
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
if (navigator.userAgent.toLowerCase().indexOf("android") > -1) {
window.location.href = 'market://details?id=<appID>';
}
if (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) {
window.location.href = 'itms-apps://itunes.apple.com/app/<appID>';
}
});
</script>
Or if working with .net can use
Dim systOS = Request.UserAgent.ToString.ToLower
If (systOS.IndexOf("android").ToString.ToLower > 0) Then
Response.Redirect("market://details?id=com.manomayelectronics")
ElseIf (systOS.IndexOf("iPod").ToString.ToLower > 0) Then
Response.Redirect("itms-apps://itunes.apple.com/app/com.manomayelectronics")
End if
OR if using PHP can use
<?php
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
//do something with this information
if( $iPod || $iPhone ){
//browser reported as an iPhone/iPod touch -- do something here
$string = "Location: <<your itunes app link>>";
header($string);
die();
}else if($iPad){
//browser reported as an iPad -- do something here
$string = "Location: <<your itunes app link>>";
header($string);
die();
}else if($Android){
//browser reported as an Android device -- do something here
$string = "Location: <<Google Play Link>>";
header($string);
die();
}
Regards Multicore Solutions. https://multicoresolutions.in/
© 2022 - 2024 — McMap. All rights reserved.