1

// This is not a duplicate. It's a follow-up question on this question and others on the same topic

I'm developing a PhoneGap app using Angular and Coffeescript, and I want it to open different views when different mobile notification are clicked (GCM and APN).

I've followed this explanation, and this question. I'm sending the name of the required view inside the message, and in the notificationHandler I'm extracting the name of the view and then switch to it.

However, it seems that when the notification is clicked, first the app is loaded, and only then does the notification handler is loaded - so the app is first opened on the default view, and only then changes to the required view. How do I fix it?

gcmNotificationsHandler.coffee:

switch e.event
      when "registered"
        ...
      when "message"
        console.log("DEBUG: mobile notification: Foreground? [#{e.foreground}] Coldstart? [#{e.coldstart}] Background? [#{not(e.foreground or e.coldstart)}]")
        notificationAction = parseNotificationParams(e.payload)

        if notificationAction.actionRequired
          if e.foreground
            console.log("DEBUG: Recieved message on foreground, moving to #{JSON.stringify(notificationAction)}")
            $state.go notificationAction.toState, notificationAction.stateParams
          else # otherwise we were launched because the user touched a notification in the notification tray.
            console.log("DEBUG: Recieved message on background, saving next state as: #{JSON.stringify(notificationAction)}")
            LocalStorage.setObject('STATE.new_notification', notificationAction)
Community
  • 1
  • 1
Yossale
  • 14,165
  • 22
  • 82
  • 109

1 Answers1

1
if (e.foreground)
{
          // ECB message event come here when your app is in foreground(not in background)
}
else
{  
  if (e.coldstart)
  {
          // ECB message event come here when you touch notification from notification tray
  }
  else
  {
         // ECB message event here when your app is in background    
  }
}

So use e.coldstart and also use $location angular js directive(or any other if not using angular js) to redirect to page.

Please refer following link :

RockStar
  • 1,304
  • 2
  • 13
  • 35