钛移动/苹果推送通知什么是插入回调最合乎逻辑的地方

问题描述:

问题,

我想实现的是对要接收通知的集中的地方,所以什么窗口或选项卡用户是通知将被接收并回调函数无论被解雇。

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.

如果一个项目在很大程度上依赖于苹果推送通知你会(以钛移动)是插入code的通知请求和回调。

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.

根据你所说的关于你的code是什么,你遇到了麻烦,因为你有多个执行上下文(即每个标签都有一个窗口url属性到另一个JavaScript文件)。而不是使用多个上下文,装载在单一上下文窗口(使用至少CommonJS的,最佳合金)。然后你就可以在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.