2

ローカル通知をキャンセルしようとしています。後で見つけられるように、ID を指定して dict を添付します。

+ (void) send:(NSString*)title actionText:(NSString *)actionText when:(NSDate *)when count:(NSInteger)count option:(NSDictionary *)options 
{
    UILocalNotification *notif = [[UILocalNotification alloc] init];
    //Setup code here...
    notif.userInfo = options;
    ALog(@"Sending notification %@ %@", notif.alertBody, notif.userInfo);
    //Print: Sending notification Task Col 0 0 {id = "1-1"};

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];
}

次に、それを見つけようとすると:

+ (void) cancelNotification:(NSString *)theId {
    for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) 
    {
        if([[aNotif.userInfo objectForKey:@"id"] isEqualToString:theId])
        {
            // Never come here: userInfo is nil!!!
        }
    }
}

userInfo は常に nil です。私はdictを送ります:

NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
        [info setObject:theId forKey:@"id"];

また

[NSMutableDictionary dictionaryWithObject:theId forKey:@"id"]

同じ結果で。(theId は NSString です)

4

1 に答える 1

0

ローカル通知は有効な場合のみ有効で、有効なタイムスタンプがあります。したがって、作成中は、有効なタイムスタンプがあることを確認してください。そのため、UIApplicaitonのscheduledNotificationsに表示されます。

コメントを教えてください。

例:localNotification.fireDate = [NSDate date];

于 2012-12-06T13:37:49.357 に答える