Reputation: 211
My website is not mobile responsive, but i have a mobile app for both Android and iOS. When people visit my website using one of these two platforms, I would like to direct them to my mobile app.
If they already have my mobile app, I would like it to auto open that app, otherwise I'd like the person to be redirected to the Google Play store or Apple AppStore to download the mobile app.
I don't know how to do that. Please help me with tips on how to do this.
<?php
class UserInfo{
private static function get_user_agent() {
return $_SERVER['HTTP_USER_AGENT'];
}
public static function get_os() {
$user_agent = self::get_user_agent();
$os_platform = "Unknown OS Platform";
$os_array = array(
'/windows nt 10/i' => 'Windows 10',
'/windows nt 6.3/i' => 'Windows 8.1',
'/windows nt 6.2/i' => 'Windows 8',
'/windows nt 6.1/i' => 'Windows 7',
'/windows nt 6.0/i' => 'Windows Vista',
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
'/windows nt 5.1/i' => 'Windows XP',
'/windows xp/i' => 'Windows XP',
'/windows nt 5.0/i' => 'Windows 2000',
'/windows me/i' => 'Windows ME',
'/win98/i' => 'Windows 98',
'/win95/i' => 'Windows 95',
'/win16/i' => 'Windows 3.11',
'/macintosh|mac os x/i' => 'Mac OS X',
'/mac_powerpc/i' => 'Mac OS 9',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
foreach ($os_array as $regex => $value) {
if (preg_match($regex, $user_agent)) {
$os_platform = $value;
}
}
return $os_platform;
}
?>
Upvotes: 1
Views: 3395
Reputation: 617
On Android, you can use app links for your domain. On iOS, you have a similar technique, universal links. Set up these in your mobile apps and redirect a user to such deep link to open content inside your app. If the app is installed, it seizes that redirect and can continue to interact with the user. And if not, a web-page hosted on the link is opened.
Upvotes: 3