我正在使用Local Notification plugin获取一个手机屏幕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
任何想法?谢谢。
答案 0 :(得分:1)
您的id参数不是字符串,但插件似乎需要id的字符串值。
答案 1 :(得分:0)
我找到了解决方案。如果您使用的是iOS 7.1,则必须替换此行
NSString* notId =[notification.userInfo objectForKey:@"id"];
这个
NSString* notId =[NSString stringWithFormat:@"%@", [notification.userInfo objectForKey:@"id"]];
方法notificationWithId。中的
感谢您的帮助!