开发者

UILocalNotification nil userInfo

开发者 https://www.devze.com 2023-04-09 09:32 出处:网络
I try to cancel a Local notification. I attach a dict with 开发者_高级运维a Id for locate it later:

I try to cancel a Local notification. I attach a dict with 开发者_高级运维a Id for locate it later:

+ (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];
}

Then when I try to locate it:

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

Always the userInfo is nil. I send the dict:

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

or

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

with the same result. (theId is NSString)


The local notification valid only, it has valid timestamp. So while you are creating make sure that, it has valid timestamp. So that, it will be present in scheduledNotifications of UIApplicaiton.

Please let me know your comments.

eg: localNotification.fireDate = [NSDate date];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号