2013-07-26 67 views
7

Tôi đang phát triển ứng dụng lịch bao gồm nhiều sự kiện (ví dụ 500 sự kiện) bao gồm sinh nhật.Tôi đang tải xuống các sự kiện tạo dịch vụ web. Tôi muốn cung cấp cho người dùng thông báo về mỗi ngày sinh tại một thời điểm cụ thể vào lúc 10:00 sáng ngày sinh nhật. Tôi đang sử dụng thông báo địa phương để lên lịch cảnh báo nhưng tôi bị kẹt vì iOS chỉ cho phép 64 thông báo cho mỗi ứng dụng và tôi có nhiều sinh nhật. Tôi không biết cách lên lịch thêm thông báo khi ứng dụng vượt quá giới hạn. Xin vui lòng đề nghị làm thế nào tôi sẽ giải quyết vấn đề này. bên dưới là mã của tôi để lên lịch thông báoCách sắp xếp thông báo cục bộ hơn trong iOS khi thông báo vượt quá giới hạn 64

- (void)scheduleNotification:(NSMutableArray *)datesArray withMessage:(NSMutableArray *)messagesArray NotificationID:(NSString *)notificationID 
{ 

    NSCalendar *calendar = [NSCalendar currentCalendar]; 

    NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; 
    [formatter setDateStyle:NSDateFormatterNoStyle]; 
    [formatter setTimeStyle:NSDateFormatterShortStyle]; 


    NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init]; 
    [formatter1 setDateStyle:NSDateFormatterMediumStyle]; 
    [formatter1 setDateFormat:@"dd/MM/yyyy"]; 

    // NSDate *myTime = [formatter dateFromString:@"06:10 PM"]; 
    NSDate *myTime = [formatter dateFromString:fireTime]; 

    for (int i = 0; i < [datesArray count]; i++) 
    { 
     NSDate *myDate = [formatter1 dateFromString:[datesArray objectAtIndex:i]]; 

     NSDateComponents *dateComponents = [calendar components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:myDate]; 
     NSDateComponents *timeComponents = [calendar components:NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:myTime]; 

     NSDateComponents *newCompoents = [[NSDateComponents alloc]init]; 

     NSDateComponents *todayComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]]; 

     int day = [dateComponents day]; 
     int month = [dateComponents month]; 

     [newCompoents setDay:[dateComponents day]]; 
     [newCompoents setMonth:[dateComponents month]]; 

     if (day >= [todayComponents day] && month >= [todayComponents month]) { 

      NSLog(@"day = %d, month = %d", day, month); 
      [newCompoents setYear:[todayComponents year]]; 
     } 
     else{ 
      NSLog(@"%d, %d", day, month); 
      [newCompoents setYear:[todayComponents year]+1]; 
     } 


     [newCompoents setHour:[timeComponents hour]]; 
     [newCompoents setMinute:[timeComponents minute]]; 

     NSDate *combDate = [calendar dateFromComponents:newCompoents]; 

     localNotif = [[UILocalNotification alloc] init]; 
     if (localNotif == nil) 
      return; 
     localNotif.fireDate = combDate; 
     localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

     // Notification details 

     NSString *message = [@"Wish" stringByAppendingFormat:@" %@%@", [messagesArray objectAtIndex:i],@" On His Birthday"]; 
     localNotif.alertBody = message; 

     // Set the action button 
     localNotif.alertAction = @"View"; 

     localNotif.soundName = UILocalNotificationDefaultSoundName; 
     localNotif.applicationIconBadgeNumber = 1; 

     // Specify custom data for the notification 
     NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:notificationID]; 
     localNotif.userInfo = infoDict; 

     // Schedule the notification 
     [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    } 

} 

sửa tôi nếu tôi phạm sai lầm và đề xuất cách lên lịch thông báo khác khi vượt quá giới hạn 64.

+0

IMO bạn có thể lên lịch lại LocalNotification khi bạn mở ứng dụng của mình, như kiểm tra Tổng số địa chỉ đã được lên lịch và nếu nó nhỏ hơn 64, hãy lên lịch lại ở đó .. – Bala

+0

và chỉ xem câu trả lời này http://stackoverflow.com/a/7721445/1059705 – Bala

+0

vâng tôi có thể đếm tổng số thông báo bằng phương pháp đó. ý của bạn là gì khi bạn mở ứng dụng của mình. tôi có cần kiểm tra số lượng trong ủy nhiệm ứng dụng của mình và lên lịch thêm thông báo không. – suhit

Trả lời

1

Tôi có vấn đề tương tự và một vài tùy chọn bổ sung có thể giúp bạn, mặc dù tất cả đều có lỗi có nghĩa là hành vi đúng không được đảm bảo.

Hãy nhớ rằng ngày sinh trùng lặp có thể hữu ích ở đây. Nếu hai người kết thúc sinh nhật trong cùng một ngày, hãy hủy và lên lịch lại với cả hai thông tin của họ được liên kết. Bạn có thể tìm các khoảng thời gian khác mà lặp lại xảy ra nếu bạn OK với một thông báo chung.

Rõ ràng, việc mã hóa người dùng của bạn để nhấn thông báo để mở ứng dụng sẽ giúp (có thể với doanh thu quảng cáo của bạn). Bạn có thể thử một thông điệp tốt đẹp cho người cuối cùng của bạn.

It's hacky, nhưng bạn có thể sử dụng geofencing (nhưng có lẽ không phải thông báo từ xa) như được mô tả ở đây: Can push notifications be used to run code without notifying user?. Nếu bạn thêm một tính năng sử dụng tính năng này, bạn thậm chí có thể có được tính năng được chấp thuận.

Tôi đã cân nhắc việc chuyển một lịch tùy chỉnh, nhưng NSCalendar được miễn phí cầu nối cho CFCalendarRef và câu chuyện có vẻ là tôi sẽ không may mắn tìm cách khai thác nó (và nhận được nó ít nhất được chấp thuận). Tôi sẽ rất vui khi được thông báo là tôi đã sai.