Chompas
Chompas

Reputation: 563

iPhone - UILocalNotification fireDate problem

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

Upvotes: 0

Views: 1042

Answers (1)

more tension
more tension

Reputation: 3352

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.

Upvotes: 3

Related Questions