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オブジェクトが1つだけ含まれているためです。これは、によって返される配列-scheduledLocalNotificationsです。

于 2011-05-04T03:16:28.250 に答える