iPhone - UILocalNotification fireDate 问题
我正在尝试从已设置的通知中获取 fireDate
这是我的代码:
NSArray *notificationArray = [[NSArray alloc] initWithObjects:[[UIApplication sharedApplication] scheduledLocalNotifications], nil];
if ([notificationArray count] > 0) {
NSDate *now = [NSDate date];
UILocalNotification *locNotification = [[UILocalNotification alloc] init];
locNotification = [notificationArray objectAtIndex:0];
NSDate *otherDate = locNotification.fireDate;
}
locNotification 有值,但当我尝试实例化 otherDate 时,最后一行我
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM fireDate]: unrecognized selector sent to instance 0x1e4e20'
在第一次抛出时得到 * 调用堆栈:
我真的不知道我做错了什么。
提前致谢
I'm trying to get the fireDate from an already set notification
Heres my code:
NSArray *notificationArray = [[NSArray alloc] initWithObjects:[[UIApplication sharedApplication] scheduledLocalNotifications], nil];
if ([notificationArray count] > 0) {
NSDate *now = [NSDate date];
UILocalNotification *locNotification = [[UILocalNotification alloc] init];
locNotification = [notificationArray objectAtIndex:0];
NSDate *otherDate = locNotification.fireDate;
}
The locNotification has the values but the last line when I try to instantiate otherDate I'm getting
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM fireDate]: unrecognized selector sent to instance 0x1e4e20'
* Call stack at first throw:
I really don't know what I'm doing wrong.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的初始化方法。您想要的不是
NSArray
的-initWithObjects:
,而是:您会得到异常,因为
notificationArray
仅包含一个对象,即-scheduledLocalNotifications
。You're using the wrong init method. Instead of
NSArray
's-initWithObjects:
, you want:You get the exception because
notificationArray
only contains one object, the array returned by-scheduledLocalNotifications
.