iPhone - UILocalNotification fireDate 问题

发布于 2024-11-04 14:11:37 字数 787 浏览 2 评论 0原文

我正在尝试从已设置的通知中获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮湿 2024-11-11 14:11:37

您使用了错误的初始化方法。您想要的不是 NSArray-initWithObjects:,而是:

NSArray *notificationArray = [[ NSArray alloc ] initWithArray:
                                    [[ UIApplication sharedApplication ]
                                       scheduledLocalNotifications ]];

您会得到异常,因为 notificationArray 仅包含一个对象,即 -scheduledLocalNotifications

You're using the wrong init method. Instead of NSArray's -initWithObjects:, you want:

NSArray *notificationArray = [[ NSArray alloc ] initWithArray:
                                    [[ UIApplication sharedApplication ]
                                       scheduledLocalNotifications ]];

You get the exception because notificationArray only contains one object, the array returned by -scheduledLocalNotifications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文