Giter VIP home page Giter VIP logo

angular-mobile-app-redirect's Introduction

Angular Mobile App Redirect

version 0.7

While developing a web application with an associated iOS application, we encountered a problem when attempting to direct our users to the iOS application from their email client.

This service provides a simple means to redirect to a native (mainly iOS) app from within an Angular application. It works by injecting a hidden iframe into the document, which causes iOS to see a navigation attempt to the protocol scheme registered with an app, which can then be handled appropriately from within the app.

Dependencies

  • Angularjs
  • An iOS application which you will be directing too.
  • Aforementioned application must have registered custom URL scheme.

Configuration

Include vokal.appRedirect in your angular app

var app = angular.module( "app", [ "vokal.appRedirect" ] );

In your angular app configuration module, you will have to include AppRedirectProvider and use it to set the protocol you want to use.

app.config( [ "AppRedirectProvider" ,
    function ( AppRedirectProvider )
    {
        //required
        AppRedirectProvider.setProtocol( "protocol" );

        // optional, set the devices to use (these are the default values)
        AppRedirectProvider.setDevices( { iPhone: true, iPad: false, Android: false } );
    } ] );

Inside one or more of your controllers, include AppRedirect, and set up logic to redirect to your native app or one of its deep links.

app.controller( "DocumentationController",
    [ "AppRedirect",
    function ( AppRedirect )
    {
        // simply redirect to the native app
        AppRedirect.redirect( "" );

        // redirect to a deep link in your app
        // AppRedirect.redirect( <path>[, <always>] );
        AppRedirect.redirect( "documentation" );
    } ] );

Or as part of your $routeProvider, using resolve:

    $routeProvider.when( "/reset-password/:token", {
        resolve: { appRedirect: function ( AppRedirect, $route )
            {
                return AppRedirect.redirect( "reset-password/" + $route.current.params.token );
            } } } );

Configuration Functions:

setProtocol( <scheme> )

  • param: scheme - String - The registered protocol for the app

Set the registered URL for a specific device.

setDevices( { iPhone: true|false, iPad: true|false, Android: true|false } )

  • param: - object - The devices that should redirect

Set the devices that should redirect.

setUserAgent( <agent> )

  • param: agent - String - Allows user agent spoofing

Primarily for testing purposes, but allows overriding of window.navigator.userAgent.

Service Functions:

redirect( <path>[, <always>] )

  • param: path - String - The path to the deep link in your app, or use an empty string to suggest the app ignore the path
  • param: always - bool - Whether to always direct to the path when the device is used, even if the path has already been visited.

Check which device the user is using and attempt to redirect to that app.

angular-mobile-app-redirect's People

Contributors

jrit avatar scottferg avatar stoicjester avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.