iOS LocalNotifications with multi-context app

You must Login before you can answer or comment on any questions.


I've got an app that schedules local notifications from an event callback through an alarm screen using the usual custom events approach. This works well. What doesn't is our notification listener in app.js:

Ti.App.iOS.addEventListener('notification', function(e)
{"local notification received: "+ e.userInfo.alarmId);
This doesn't seem to fire. We need it to fire once the app loads/resumes from background so we know which alarm to load. Has anyone any experience of this?

Using a small test app with a single context everything works fine so I'm wondering if they're related. That said I thought app.js context was always loaded. A further point I wondered is if it was because the event callback was on a different thread? Or maybe even the alarm screen itself? Been messing with this for hours and got nowhere!


— asked 4 years ago by George Palmer
  • can you provide more code? where is the resume event code, where is the code that you are firing the event?

    yes the doc, might be a little lite...but you haven't provided much here to go on.

    How to ask a question

    — commented 4 years ago by Aaron Saunders

  • As far as I understand it the code that handles resume is unconnected to local notifications but maybe that's what I'm missing. Anyway here's all the related code:

    saveNotification = function(e) {
        alarmId = e.alarmId;
            alertBody:'Alarm\n Do something',
            sound: "default",
            date:new Date(new Date().getTime() + 3000),
    Ti.App.addEventListener('saveNotification', saveNotification);
    Ti.App.iOS.addEventListener('notification', function(e){"local notification received: "+ e.userInfo.alarmId);
    Ti.App.addEventListener('resume',function(e){"app is resuming from the background");
    Ti.App.addEventListener('resumed',function(e){"app has resumed from the background");
    Ti.App.addEventListener('pause',function(e){"app was paused from the foreground");
    and then in my other window:
    Ti.App.fireEvent('saveNotification', {'alarmId':123456});
    Note sending the local notification at 3s after the event was just to speed up testing. It doesn't make any difference if it's 5 minutes.

    — commented 4 years ago by George Palmer

  • Just to clarify the other window is a separate context

    — commented 4 years ago by George Palmer

  • Show 5 more comments

2 Answers

what is this?

Ti.App.iOS.addEventListener('notification', function(e)
you probably should not be attaching objects to the Ti.App namespace so I would start with changing that.

— answered 4 years ago by Aaron Saunders
answer permalink
  • That's how the Kitchen Sink does unless I'm missing something?

    — commented 4 years ago by George Palmer

  • my mistake, misread and no way to delete or edit after submit is pressed

    — commented 4 years ago by Aaron Saunders

It appears (at least as of iOS6 and ti mobile 3.0.2) that the Ti.App.fireEvent method blocks while there are any other contexts running inside of application event handlers. As far as I can tell the best way to work around this problem is to do multithreading via web workers running inside a hidden WebView.

Your Answer

Think you can help? Login to answer this question!