0

I'm using Local Notification plugin for a phonegap iOS app. When I try to add a new Notification, the app throw a NSInvalidArgumentException.

Here is the code when i add a notification:

var now                  = new Date().getTime(),
        _60_seconds_from_now = new Date(now + 60*1000);     
window.plugin.notification.local.add({
                                              id:      1,
                                              title:   'Reminder',
                                              message: 'Dont forget to buy some flowers.',
                                              repeat:  false,
                                              date:    _60_seconds_from_now
                                         });

And here is the output


Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xa26c650'
*** First throw call stack:
(
    0   CoreFoundation                      0x000dd1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x021948e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0017a243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x000cd50b ___forwarding___ + 1019
    4   CoreFoundation                      0x000cd0ee _CF_forwarding_prep_0 + 14
    5   OPS                                 0x000276e9 -[APPLocalNotification notificationWithId:] + 521
    6   OPS                                 0x00027246 -[APPLocalNotification isNotificationScheduledWithId:] + 86
    7   OPS                                 0x00023458 __28-[APPLocalNotification add:]_block_invoke + 200
    8   libdispatch.dylib                   0x027527b8 _dispatch_call_block_and_release + 15
    9   libdispatch.dylib                   0x027674d0 _dispatch_client_callout + 14
    10  libdispatch.dylib                   0x02755eb7 _dispatch_root_queue_drain + 291
    11  libdispatch.dylib                   0x02756127 _dispatch_worker_thread2 + 39
    12  libsystem_pthread.dylib             0x02a96dab _pthread_wqthread + 336
    13  libsystem_pthread.dylib             0x02a9acce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException

any idea? Thank you.

  • You are getting the error from the native side, one of the parameters you are passing is different type than expected perhaps. You can debug in xcode and resolve the problem easily. Also there may be several local notification plugins, I don't see which of them you are using. – mentat Aug 30 '14 at 12:33
  • Hi @mentat, I'm using this plugin https://github.com/katzer/cordova-plugin-local-notifications Also, I debugged in xcode and i didn't find anything strange – Sergio Pacheco Aug 30 '14 at 14:22

2 Answers2

1

Your id param is not string, but the plugin seem to require a string value for id.

mentat
  • 2,748
  • 1
  • 21
  • 40
0

I find the solution. If you are using iOS 7.1, you must replace this line

 NSString* notId =[notification.userInfo objectForKey:@"id"];

for this

 NSString* notId =[NSString stringWithFormat:@"%@", [notification.userInfo objectForKey:@"id"]];

in the method notificationWithId.

Thanks for the help!