【问题标题】:iPhone - UILocalNotification fireDate problemiPhone - UILocalNotification fireDate 问题
【发布时间】:2011-05-04 03:08:36
【问题描述】:

我正在尝试从已设置的通知中获取 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; 
 }

当我尝试实例化我得到的 otherDate 时,locNotification 具有值,但最后一行

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM fireDate]: unrecognized selector sent to instance 0x1e4e20'

* 首次抛出时调用堆栈:

我真的不知道我做错了什么。

提前致谢

【问题讨论】:

    标签: iphone date nsdate uilocalnotification


    【解决方案1】:

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

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

    因为notificationArray 只包含一个对象,即-scheduledLocalNotifications 返回的数组,您会得到异常。

    【讨论】:

    • 就是这样。奇怪的是,我在错误的初始化数组中得到了结果。对不起。新手问题=)非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多