钛金手机/苹果推送通知 插入回调最合乎逻辑的地方是什么 [英] Titanium mobile / Apple Push notifications What is the most logical place to insert the callback

查看:34
本文介绍了钛金手机/苹果推送通知 插入回调最合乎逻辑的地方是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题,

我想要实现的是有一个集中的地方来接收通知,所以无论用户在哪个窗口或选项卡上都会收到通知并触发回调函数.

What I want to achieve is to have a centralised place for the notifications to be received, so no matter on what window or tab a user is the notification will be received and callback functions to be fired.

如果一个项目严重依赖 Apple 推送通知,那么(在 Titanium Mobile 中)是插入通知请求和回调代码的最佳位置.

If a project relies heavily on the Apple Push Notifications what would (In Titanium Mobile) be the best place to insert the code for the notification requests and callback.

我认为这会自动发生,但事实并非如此,目前我将 registerForPushNotifications 放在一个文件中,该文件包含在每个窗口中 &标签.但是,如果发送推送通知,则会在每个选项卡上收到它,但如果我更改选项卡,则会再次收到通知.

I thought this would happen automatically but it does not, currently I have the registerForPushNotifications placed in a file that is included on every window & tab. But if a push notification is send then it is received on every tab, but if I change the tab the notification is again received.

因此,如果我将 registerForPushNotifications 放在包含的文件中,即使触发一次,也会多次收到通知.

So if I place the registerForPushNotifications on a included file the notification will be received numerous times even tough it is fired once.

推荐答案

根据您对代码的描述,您遇到了麻烦,因为您有多个执行上下文(即每个选项卡都有一个带有 url 属性的窗口到另一个 JavaScript 文件).与其使用多个上下文,不如在单个上下文中加载窗口(至少使用 CommonJS,最好使用 Alloy).然后您可以在 app.js 或从您的 app.js 调用的 CommonJS 模块中注册您的回调.在那种情况下,您的问题不会存在.

Based on what you've said about your code, you're having trouble because you have multiple execution contexts (i.e. every tab has a window with the url property to another JavaScript file). Rather than using multiple contexts, load up the windows in a single context (using at least CommonJS, and optimally Alloy). Then you can register your callback in app.js, or in a CommonJS module called from your app.js. Your problem wouldn't exist in that scenario.

这篇关于钛金手机/苹果推送通知 插入回调最合乎逻辑的地方是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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