[iOS] URL schema handling

I’m assuming you’ve already got the URL scheme handling properly.

If not, the @aaronksaunders answer of the LaunchMyApp plugin is the best way to go. It works really well.

Next ->

I THINK your problem is that you can’t figure out how to integrate it into Ionic. As @mhartington said, this isn’t really an Ionic question. It’s more of an AngularJS question. Generally, speaking, you don’t want external code to be interacting with an Angular app. However, sometimes it is necessary. In this case, it’s necessary because the URL handler MUST be a global function.

So, you need to find some way to let the external, global function communicate with Angular. There’s a great SO post on that here : http://stackoverflow.com/questions/10490570/call-angular-js-from-legacy-code

Here’s how to make this work. Maybe I’ll do a blog post on this. The gist is that you have a controller that will always be present (don’t use on a controller that may not be active). The handler finds the element (body) and gets the controller scope of it. Then, it calls a method on that controller scope.

Put index.html:

<body ng-controller="AppLaunchedController">

Put this in your default view :

<h2 class="padding">Has Launched : {{test.hasLaunched}}</h2>

Create a controller like this :

.controller('AppLaunchedController', function($scope) {

	$scope.test = {
		hasLaunched : 'NO'
	};

	$scope.reportAppLaunched = function(url) {

		console.log('The app launched with URL : ' + url);
		
		$scope.$apply( function() {
			$scope.test.hasLaunched = 'YES';

		})
	}
})

Then perhaps at the bottom of your app.js

function handleOpenURL(url) {

    var body = document.getElementsByTagName("body")[0];
    var appLaunchedController = angular.element(body).scope();
    appLaunchedController.reportAppLaunched(url);

}