如何判断是否该应用程序是打开或恢复为钛推送通知的结果? [英] How do I tell if the app was opened or resumed as a result of a push notification in Titanium?

查看:223
本文介绍了如何判断是否该应用程序是打开或恢复为钛推送通知的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在钛不同的方式处理一推依赖于应用程序是否是在推到的时候开?

How do you handle a push differently in Titanium depending on whether the app was open at the time the push arrived?

在一个推送通知进来,我的应用程序正在运行,我想弹出一个消息提供给用户带到项目的通知指。如果应用程序是封闭的,而用户点击推送通知,并会导致应用程序打开,我想直接将用户带到该项目没有一个弹出窗口。

When a push notification comes in and my app is running, I would like to pop up a message offering to take the user to the item the notification refers to. If the app is closed, and the user taps on the push notice and causes the app to open, I would like to take the user directly to the item without a popup.

钛的registerForPushNotifications似乎只有一个回调,回调,无论应用程序的状态被称为当推到来。据<一个href=\"http://stackoverflow.com/questions/1998196/how-do-i-tell-if-my-iphone-app-is-running-when-a-push-notification-is-received\">How我知道我的iPhone应用程序在运行时接收推送通知时?您可以在目标C使用didReceiveRemoteNotification和didFinishLaunchingWithOptions,但钛似乎并没有向这些单独的访问。

Titanium's registerForPushNotifications seems to only have one callback, "callback", which is called regardless of the app's state when the push arrives. According to How do I tell if my iPhone app is running when a Push Notification is received? you can use didReceiveRemoteNotification and didFinishLaunchingWithOptions in Objective C, but Titanium doesn't seem to provide separate access to those.

推荐答案

在'回调'的功能将得到'简历'之后,如果用户来自的通知解雇了。

The 'callback' function will get fired right after 'resume' if user comes from a notification.

所以,我会处理你的情况通过以下方式:

So I would handle your case the following way:

有一个变量来跟踪阉应用程序被暂停或停止(一拉VAR is_paused = FALSE;运行时)。
is_paused将在Ti.App暂停事件被切换到真实切换回假状态,超时(1秒会做)在Ti.App'恢复'事件。

have a variable to track wether app is paused or not (a la var is_paused = false; when running). is_paused would be switched to true upon Ti.App 'pause' event and switched back to false state with a timeout (1second will do) upon Ti.App 'resume' event.

然后就可以通过检查在回调函数不同的功能,如果is_paused变种是真的还是假的:

Then you can have different functionality in callback function by checking if is_paused var is true or false:

//in notification callback
if(is_paused){ 
   //user is coming from background (do your thing automatically)
}else{
  //user is in app (display the alert)
}

这篇关于如何判断是否该应用程序是打开或恢复为钛推送通知的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆