Eri*_*son 5 iphone titanium push-notification apple-push-notifications titanium-mobile
你如何处理Titanium中的推送方式取决于推送到达时应用程序是否打开?
当推送通知进入并且我的应用程序正在运行时,我想弹出一个消息提供,以将用户带到通知所引用的项目.如果应用程序关闭,并且用户点击推送通知并导致应用程序打开,我想直接将用户带到该项目而无需弹出窗口.
Titanium的registerForPushNotifications似乎只有一个回调"回调",无论推送到达时应用程序的状态如何都会被调用.根据收到推送通知时如何判断我的iPhone应用程序是否正在运行?您可以在Objective C中使用didReceiveRemoteNotification和didFinishLaunchingWithOptions,但Titanium似乎不提供对它们的单独访问.
如果用户收到通知,“回调”函数将在“恢复”后立即触发。
所以我会按照以下方式处理你的情况:
有一个变量来跟踪应用程序是否暂停(运行时 var is_paused = false; )。is_paused 将在 Ti.App 'pause' 事件时切换为 true,并在 Ti.App 'resume' 事件时切换回 false 状态并超时(1 秒即可)。
然后,您可以通过检查 is_paused var 是 true 还是 false 来在回调函数中拥有不同的功能:
//in notification callback
if(is_paused){
//user is coming from background (do your thing automatically)
}else{
//user is in app (display the alert)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1340 次 |
| 最近记录: |