2011-10-07 27 views
12

thực sự đang phát triển một dự án báo động, bây giờ tôi có nghi ngờ về thông báo Địa phương. làm thế nào tôi có thể xác định một thông báo cụ thể. chúng tôi thậm chí không thể đặt thẻ thành thông báo địa phương, sau đó làm cách nào tôi có thể phân biệt chúng.cách xác định thông báo cụ thể trong ios sdk

dụ:

thông báo: 1

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = selectedDate; 
    localNotification.alertBody = @"you got work"; 
    localNotification.alertAction = @"Snooze"; 
    localNotification.repeatInterval = NSDayCalendarUnit; 
    localNotification.soundName = UILocalNotificationDefaultSoundName; 

    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil]; 
    localNotification.userInfo = infoDict; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    [localNotification release]; 

thông báo: 2,

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = another selectedDate; 
    localNotification.alertBody = @"i got work"; 
    localNotification.alertAction = @"Snooze"; 
    localNotification.repeatInterval = NSDayCalendarUnit; 
    localNotification.soundName = UILocalNotificationDefaultSoundName; 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil]; 
    localNotification.userInfo = infoDict; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    [localNotification release]; 

bây giờ tôi đang ở trong tình huống để xóa các thông báo thứ hai làm thế nào tôi có thể làm điều đó ... hãy giúp tôi .. cảm ơn trước ..

Trả lời

8

Đoán của tôi là sử dụng userInfo để phân biệt các thông báo cục bộ sẽ là một ý tưởng tốt hơn nhưng bạn cần đặt userInfo của thông báo cục bộ.

Giống như bạn có thể làm một cái gì đó như thế này

 
if ([Your_notification_Object.userInfo valueForKey:@"Key 1"][email protected]"Object 1") { 

      NSLog(@"This is notification 1"); 
     } 

bây giờ cho tức là yêu cầu thứ hai của bạn cho phần xóa bạn có muốn xóa các thông báo khi nó được xác định là n1 hoặc n2 thì trong trường hợp đó bạn có thể sửa đổi mã ở trên và thêm này

 
if ([Your_notification_Object.userInfo valueForKey:@"Key 1"][email protected]"Object 1") { 

      NSLog(@"This is notification 1"); 
[[UIApplication sharedApplication] cancelLocalNotification:Your_notification_Object]; 


     } 

Đặt mã trên theo sự thuận tiện của bạn

Các vấn đề liên quan