本地通知phonegap ios



我正在为phonegap iOS应用程序使用本地通知插件。当我尝试添加新通知时,应用程序会抛出NSInvalidArgumentException。

这是我添加通知时的代码:

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
                                         });

这是的输出


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

知道吗?非常感谢。

您的id参数不是字符串,但插件似乎需要id的字符串值。

我找到了解决方案。如果你使用的是iOS 7.1,你必须更换这一行

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

对于这个

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

在方法notificationWithId中。

谢谢你的帮助!

最新更新