Thursday, May 25, 2017

How to set Deep Linking in Laravel 5.4

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

3 comments:

  1. Can you please explain how it will work?

    ReplyDelete
  2. Did you hear there's a 12 word sentence you can tell your man... that will induce intense feelings of love and instinctual attraction to you buried within his heart?

    That's because hidden in these 12 words is a "secret signal" that fuels a man's instinct to love, admire and guard you with his entire heart...

    12 Words Will Trigger A Man's Love Impulse

    This instinct is so built-in to a man's mind that it will make him try harder than before to do his best at looking after your relationship.

    In fact, triggering this all-powerful instinct is absolutely essential to having the best possible relationship with your man that the moment you send your man one of the "Secret Signals"...

    ...You'll soon notice him expose his mind and soul to you in such a way he's never expressed before and he will distinguish you as the only woman in the world who has ever truly fascinated him.

    ReplyDelete