【问题标题】:PhoneGap Open page based on notification contentPhoneGap 根据通知内容打开页面
【发布时间】:2014-12-27 16:05:08
【问题描述】:

// 这不是重复的。这是this question 和其他同一主题的后续问题

我正在使用 Angular 和 Coffeescript 开发一个 PhoneGap 应用程序,我希望它在单击不同的移动通知(GCM 和 APN)时打开不同的视图。

我关注了这个explanation 和这个question。我在消息中发送所需视图的名称,并在 notificationHandler 中提取视图的名称,然后切换到它。

但是,似乎在单击通知时,首先加载应用程序,然后才加载通知处理程序 - 因此应用程序首先在默认视图上打开,然后才更改为所需的视图。我该如何解决?

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)

【问题讨论】:

    标签: android angularjs cordova coffeescript


    【解决方案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    
      }
    }
    

    所以使用 e.coldstart 并使用 $location angular js 指令(或任何其他,如果不使用 angular js)重定向到页面。

    请参考以下链接:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多