【问题标题】:UILocalNotification nil userInfoUILocalNotification 无用户信息
【发布时间】:2011-11-26 10:38:40
【问题描述】:

我尝试取消本地通知。我附上一个带有 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)

【问题讨论】:

    标签: xcode4 ios4 ios5 automatic-ref-counting


    【解决方案1】:

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

    请告诉我你的cmets。

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

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-30
      • 2020-01-31
      相关资源
      最近更新 更多