How to set Deep Linking in Laravel 5.4:
For this
public function redirectDeepLink(Request $request) {
try {
$device = $this->isMobileDevice();
$id = $request->input('itemId');
$app = config('constant.DEEPLINKING.APP') . $id;
$data = array();
if ($device == 'iPhone') {
$data['primaryRedirection'] = $app;
$data['secndaryRedirection'] = config('constant.DEEPLINKING.APPSTORE');
} else {
$redirect = config('constant.DEEPLINKING.WEBSITE');
return redirect($redirect);
}
return View('deep-linking', $data);
} catch (Exception $e) {
Log::error(__METHOD__ . ' ' . $e->getMessage());
return Utilities::responseError(__('messages.SOMETHING_WENT_WRONG') . $e->getMessage());
}
}
private function isMobileDevice() {
$aMobileUA = array(
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
//Return true if Mobile User Agent is detected
foreach ($aMobileUA as $sMobileKey => $sMobileOS) {
if (preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])) {
return $sMobileOS;
}
}
//Otherwise return false..
return false;
}
Here:
config('constant.DEEPLINKING.APP') is Path of App
config('constant.DEEPLINKING.APPSTORE') is Path of App in Appstore
config('constant.DEEPLINKING.WEBSITE') is website domain
in deep-linking.blade.php add this code
<html>
<head>
</head>
<body>
<script>
window.location = "{{$primaryRedirection}}"; // will result in error message if app not installed
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "{{$secndaryRedirection}}";
}, 500);
</script>
</body>
</html>
Thanks
For this
public function redirectDeepLink(Request $request) {
try {
$device = $this->isMobileDevice();
$id = $request->input('itemId');
$app = config('constant.DEEPLINKING.APP') . $id;
$data = array();
if ($device == 'iPhone') {
$data['primaryRedirection'] = $app;
$data['secndaryRedirection'] = config('constant.DEEPLINKING.APPSTORE');
} else {
$redirect = config('constant.DEEPLINKING.WEBSITE');
return redirect($redirect);
}
return View('deep-linking', $data);
} catch (Exception $e) {
Log::error(__METHOD__ . ' ' . $e->getMessage());
return Utilities::responseError(__('messages.SOMETHING_WENT_WRONG') . $e->getMessage());
}
}
private function isMobileDevice() {
$aMobileUA = array(
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
//Return true if Mobile User Agent is detected
foreach ($aMobileUA as $sMobileKey => $sMobileOS) {
if (preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])) {
return $sMobileOS;
}
}
//Otherwise return false..
return false;
}
Here:
config('constant.DEEPLINKING.APP') is Path of App
config('constant.DEEPLINKING.APPSTORE') is Path of App in Appstore
config('constant.DEEPLINKING.WEBSITE') is website domain
in deep-linking.blade.php add this code
<html>
<head>
</head>
<body>
<script>
window.location = "{{$primaryRedirection}}"; // will result in error message if app not installed
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "{{$secndaryRedirection}}";
}, 500);
</script>
</body>
</html>
Thanks