2011-09-27 32 views
2

我嘗試取消本地通知。我附上一個字典有ID爲以後找到它:UILocalNotification零用戶信息

+ (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!!! 
     } 
    } 
} 

始終將用戶信息是零。我送字典:

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

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

具有相同的結果。 (該ID是NSString)

回答

0

本地通知只有效,它有有效的時間戳。所以在創建時請確保它有有效的時間戳。因此,它將出現在UIApplicaiton的預定通知中。

請讓我知道您的意見。

例如:localNotification.fireDate = [NSDate date];