iPhone - UILocalNotification fireDate问题

时间:2011-05-04 03:08:36

标签: iphone date nsdate uilocalnotification

我正在尝试从已设置的通知中获取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有值但是最后一行

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

* 首次调用堆栈:

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

提前致谢

1 个答案:

答案 0 :(得分:3)

您使用的是错误的init方法。而不是NSArray的{​​{1}},您需要:

-initWithObjects:

您得到异常,因为NSArray *notificationArray = [[ NSArray alloc ] initWithArray: [[ UIApplication sharedApplication ] scheduledLocalNotifications ]]; 只包含一个对象,notificationArray返回的数组。