I recently got a project from another team and I'm working on fixing the integration of your service in an ionic framework applicationusing the urbanairship-cordova plugin, for my company.

I did some troubleshooting and saw on our back-end that no user got an "urban_airship_channel_id" and an "urban_airship_platform". 

 

I stopped the troubleshooting at this function in our client side application:

 

      document.addEventListener('urbanairship.registration', (function(event) {

 

        var user;

        if (event.error) {

          $rootScope.$broadcast('notification:register:error', event.error);

        } else {

          user = {

            urban_airship_channel_id: event.channelID,

            urban_airship_platform: $cordovaDevice.getDevice().platform.toLowerCase()

          };

          console.log(user);

          DeviceAPI.update({

            user: user,

            locale: localization.getLocale()

          }, function(success) {

            return $rootScope.$broadcast('notification:register:success', event.deviceToken);

          }, function(failure) {

            return console.log(failure);

          });

        }

 

      }), false);

 

The parent function of this listener is executed, but this event is never triggered and the user doesn't get the values. 

I don't receive any kind of exception.

 

Can you please help me understand how the urbanairship.registration event is suppose to be triggered?

 

Didn't find what you were looking for?

New post

Comments

1 comment

  • After a session of troubleshooting with the support team I figured out that urbanairship.registration is triggered at the first launch.

    Not really sure what my problem was, I built the notifications from scratch, here is my code:

     

    var Notifications;

    Notifications = function($rootScope, session, localization, DeviceAPI, $cordovaDevice) {
    var onDeviceReady = function() {
    console.log("Device ready!")
    UAirship.setNotificationTypes(UAirship.notificationType.sound | UAirship.notificationType.alert | UAirship.notificationType.badge);
    UAirship.setUserNotificationsEnabled(true, function(enabled) {
    $rootScope.$broadcast('notification:enable', enabled);
    });
    // Incoming message callback
    var onPushReceived = function(event) {
    if (event.message) {
    $rootScope.$broadcast('notification:push_message', event);
    console.log("Received push: " + event.message)
    } else {
    console.log("No incoming message")
    }
    }
    // Incoming message callback
    var onLaunchedFromPush = function(event) {
    if (event.message) {
    console.log("Launched from push: " + event.message)
    } else {
    console.log("No incoming message")
    }
    }
    // Registration callback
    var onRegistration = function(event) {
    var user;
    if (!event.error) {
    $rootScope.$broadcast('notification:register:success', event.deviceToken);
    console.log("Reg Success: " + event.channelID)
    user = {
    urban_airship_channel_id: event.channelID,
    urban_airship_platform: $cordovaDevice.getDevice().platform.toLowerCase()
    };
    console.log(user);
    DeviceAPI.update({
    user: user,
    user_id: session.getUser().id
    }, function(success) {
    $rootScope.$broadcast('notification:register:success', event.deviceToken);
    console.log("urbanairship details sent to the user")
    }, function(failure) {
    console.log(failure);
    });
    } else {
    $rootScope.$broadcast('notification:register:error', event.error);
    console.log(event.error)
    }
    }
    // Register for any urban airship events
    document.addEventListener("urbanairship.registration", onRegistration, false)
    document.addEventListener("urbanairship.push", onPushReceived, false)

    // Get the launch notification if its available.
    UAirship.getLaunchNotification(true, onLaunchedFromPush)
    }

    this.register = function(push){
    if (push){
    console.log("user push allowed")
    document.addEventListener("deviceready", onDeviceReady, false)
    }
    else
    {
    console.log("user push disabled")
    }
    }

    this.unregister = function(){
    console.log("unregister")
    var user;
    user = {
    urban_airship_channel_id: "",
    urban_airship_platform: ""
    };
    DeviceAPI.update({
    user: user,
    user_id: session.getUser().id
    }, function(success) {
    console.log("urbanairship details deleted removed from user")
    }, function(failure) {
    console.log(failure);
    });
    }
    };

    angular.module('stAuth').service('notifications', Notifications);

    Comment actions Permalink
    0

Please sign in to leave a comment.