0

I'm trying to build an alarm clock app, and am using the localNotification and trying to adapt the code from http://www.drewdahlman.com/meusLabs/?p=84.

My app is a combination of phonegap with backbone. I'm setting the localNotification with

plugins.localNotification.add({ 
           date: set_alarm, 
           message: 'Wakey Wakey...', 
           badge: 0, 
           id: 12, 
           sound:'Alarm.cab',
           background:'MyApp.Views.Alarm.notification()',
           foreground:'MyApp.Views.Alarm.notification()' 
           });

later, in my MyApp.Views.Alarm i have

notification: function(){
   alert('alarm');
}

unfortunately, this alert is never triggered in iOS simulator.

xCode outputs the following

2012-07-25 10:06:25.054 Wakey[8253:13403] 
  Notification Set: 2012-07-25 10:07:25 +0000 
  (ID: 12, Badge: 0, sound: Alarm_01.cab,
   background: Wakey.Views.Alarm.notification(), 
   foreground: Wakey.Views.Alarm.notification())
2012-07-25 10:06:25.055 Wakey[8253:13403] [INFO] 2012-07-25T10:07:25.044Z
2012-07-25 10:06:25.056 Wakey[8253:13403] [INFO] "2012-07-25T10:07:25.044Z"
2012-07-25 10:06:25.058 Wakey[8253:13403] I was currently active

The strange part is, I can't find anywhere the in my code where I'm outputing 'I was currently active'. Which I find strange, and it isn't in the localNotification plugin files.

Any suggestions as to why my notifications aren't being triggered?

pedalpete
  • 21,076
  • 45
  • 128
  • 239

1 Answers1

1

change the formatting on your foreground and background functions.

plugins.localNotification.add({ 
           date: set_alarm, 
           message: 'Wakey Wakey...', 
           badge: 0, 
           id: 12, 
           sound:'Alarm.cab',
           background:'MyApp.Views.Alarm.notification',
           foreground:'MyApp.Views.Alarm.notification' 
           });

On the objective C side of things the functions are called and have the id of the notification included as an argument.

The most recent update of the plugin added the ability to have the id's included in the callback, and documentation needs to be updated.

cheers!

EDIT - I am updating the tutorial, a lot has changed since the original post and I need to consolidate all of the posts!

Drew Dahlman
  • 4,952
  • 1
  • 22
  • 34
  • thanks Drew (sorry if you saw the last comment, I was editing it and ran into a problem). Unfortunately, that didn't solve the problem. When I change background and foreground to `alert("trigger");`, everything works no problem, but not when I try `MyApp.Views.Alarm.notification`. That is within the backbone view `MyApp.Views.Alarm`. Could that be the problem? Any advice on debugging this? I'm new to xcode, and the xcode console shows no errors. Thanks – pedalpete Jul 25 '12 at 05:29
  • ahhhh the joys of deving blindly :P okay so the plugin works as expected when outside of your backbone app, but when in your app it has issues right? sounds like a scope issue... obj-c is trying to call that function but when it tries to nothing is there... – Drew Dahlman Jul 25 '12 at 05:32
  • thanks again drew. So I'm not alone on that heh? I was surprised to not be able to see any errors. The joys of a good browser. Thanks for your help, and the awesome tutorials you've been putting together. – pedalpete Jul 25 '12 at 08:01
  • Have you tried https://github.com/apache/incubator-cordova-weinre? Weinre is a debugging tool that can help answer these kind of questions. Give that a shot – Drew Dahlman Jul 25 '12 at 14:28
  • 1
    I hadn't heard of that Drew, I'll give it a shot. – pedalpete Jul 26 '12 at 00:22