2

我尝试取消本地通知。我附加了一个带有 Id 的字典,以便稍后找到它:

+ (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 始终为零。我发送字典:

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

或者

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

结果相同。(theId 是 NSString)

4

1 回答 1

0

本地通知仅有效,它具有有效的时间戳。因此,在您创建时,请确保它具有有效的时间戳。因此,它将出现在 UIApplicaiton 的 scheduleNotifications 中。

请让我知道您的意见。

例如:localNotification.fireDate = [NSDate 日期];

于 2012-12-06T13:37:49.357 回答