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'

*在第一次抛出时调用堆栈:

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

提前致谢

4

1 回答 1

3

您使用了错误的 init 方法。而不是NSArray's -initWithObjects:,你想要:

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

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

于 2011-05-04T03:16:28.250 回答