本地通知phonegap ios
问题描述:
我使用Local Notification plugin作为phonegap iOS应用程序。当我尝试添加新的通知时,应用程序抛出一个NSInvalidArgumentException。本地通知phonegap ios
下面是代码当我添加一个通知:
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
什么想法?谢谢。
答
我找到解决方案。如果您使用的是iOS 7.1,则必须更换这行
NSString* notId =[notification.userInfo objectForKey:@"id"];
此
NSString* notId =[NSString stringWithFormat:@"%@", [notification.userInfo objectForKey:@"id"]];
的方法notificationWithId
。
感谢您的帮助!
答
你的ID参数不是字符串,但插件似乎需要一个字符串值的ID。
您从本机端收到错误,您传递的参数之一与预期的类型可能不同。您可以在xcode中调试并轻松解决问题。也可能有几个本地通知插件,我看不到你正在使用哪一个。 – mentat 2014-08-30 12:33:58
嗨@mentat,我使用这个插件https://github.com/katzer/cordova-plugin-local-notifications此外,我在xcode中调试,我没有发现任何奇怪的东西 – 2014-08-30 14:22:44