问题
Question,
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.
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.
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.
So if I place the registerForPushNotifications
on a included file the notification will be received numerous times even tough it is fired once.
回答1:
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.
回答2:
if you are using push notifications with ACS, look here http://developer.appcelerator.com/question/135751/acs---push-notifications---tutorial
more information here
http://blog.teemusk.com/2012/05/building-server-push-notifications-with-appcelerator-titanium-cloud/
来源:https://stackoverflow.com/questions/14231470/titanium-mobile-apple-push-notifications-what-is-the-most-logical-place-to-ins