[iOS] URL schema handling

I tested a different approach using events.

Basically in my app.js my handleOpenURL function trigger a custom event with the url received as payload.

function handleOpenURL(url) {
  var event = new CustomEvent('SamklUrl', {detail: {'url': url}});
  setTimeout( function() {
      window.dispatchEvent(event);
    },
    0
  );
}

Then I added a run function to the main angular.module where I intercept the event.

.run(['$state', '$window',
  function($state, $window) {
    $window.addEventListener('SamklUrl', function(e) {
       if(e.detail.url==='zut://zut') {
         $state.go('invite', e.detail.url);
       }
    });
  }
])

Of course you can inject any Service/Factory you need there…

4 Likes