2012-06-13 55 views
0

在我的應用程序中,我有朋友列表說:3個朋友,所有這三個都有生日的詳細信息。我需要安排本地通知以顯示他們的b'days警報。我知道並處理了本地通知,但我將如何處理這些多重通知?iPhone中的多個本地通知

我放火日期「for循環」。就是它正確,請參閱該代碼。

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) 
     return; 
    NSDateFormatter *formatter = [[[NSDateFormatter alloc]init]autorelease]; 
    for (int i = 0; i< [delegate.viewController.contactList count] ; i++) { 
     NSString *birthday = [[myArray objectAtIndex:i]objectForKey:@"birthday"]; 

     [formatter setDateFormat:@"MM/dd/yyyy"]; 
     NSDate *date = [formatter dateFromString:birthday]; 

     localNotif.fireDate = [date dateByAddingTimeInterval:10]; 
     localNotif.timeZone = [NSTimeZone defaultTimeZone]; 
     NSLog(@"local %@",localNotif.fireDate); 
    } 

    localNotif.applicationIconBadgeNumber = 1; 

    NSString *itemName = @「Friend Name"; 
    NSDictionary *userDict = [NSDictionary dictionaryWithObjectAndKey:itemName,@"msg", nil]; 

    localNotif.userInfo = userDict; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    [localNotif release]; 

我想要什麼,在這種方法只我要基於所有的朋友訂的通知如果我錯過了任何東西,請告訴我

回答

3

只需製作三個(或更多)本地通知並使用scheduleLocalNotification:安排其中的每一個都有什麼問題? 例如,這是我在我的項目中所做的:

for (int i = 0; i < 6; i++) { 
    UILocalNotification *localNotification = [prototypeNotification copy]; 
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:dates]; 
    [notifications addObject:localNotification]; 


    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

    [localNotification release]; 
} 

UPD

// ...this goes earlier: 
static NotificationController *sharedNotificationController = nil; 

- (id) init 
{ 
    if (self = [super init]) { 
     notifications = [[NSMutableArray alloc] init]; 

     prototypeNotification = [[UILocalNotification alloc] init]; 
     prototypeNotification.repeatCalendar = [NSCalendar currentCalendar]; 
     prototypeNotification.repeatInterval = NSMinuteCalendarUnit; 

     prototypeNotification.timeZone = [NSTimeZone defaultTimeZone]; 
     prototypeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0]; 
     prototypeNotification.applicationIconBadgeNumber = 0; 
     prototypeNotification.alertBody = NSLocalizedString(@"Body", nil); 
     prototypeNotification.alertAction = NSLocalizedString(@"Action", nil); 

     enabled_ = NO; 
    } 
    return self; 
} 
+0

日Thnx哥們!但是如果m有超過500的朋友,並且必須安排每個人。不是性能有效嗎? – iCoder4777

+0

這只是通知(小窗口顯示兩個文本字符串)。我不認爲業績會受到影響。 –

+0

這裏是什麼原型通知,它是一個屬性? – iCoder4777