//这不是重复的。这是关于同一主题的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)
答案 0 :(得分: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指令(或任何其他如果不使用角度js)重定向到页面。
请参阅以下链接: