每日UILocalNotification的问题

时间:2012-03-16 08:40:42

标签: iphone objective-c ios xcode ipad

我已经创建了一个通知系统,每天都会在上午12:02 推送通知,但我不知道我的代码是否正常工作,只需一两天推送应用程序的通知!你能帮我找到问题吗?

- (void) LocalNotificationManager {


    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSPersianCalendar];
    NSDate *now = [NSDate date];    
    NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit ) fromDate: now];



    [componentsForFireDate year];
    [componentsForFireDate month];
    [componentsForFireDate day];
    [componentsForFireDate setHour:00];
    [componentsForFireDate setMinute:2];
    [componentsForFireDate second];

    NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];

    notification = [[UILocalNotification alloc]init];
    notification.fireDate = fireDateOfNotification;
    notification.timeZone = [NSTimeZone localTimeZone]; 
    notification.repeatInterval= NSYearCalendarUnit; 


    NSString *date = [self showPersianFullDate];
    notification.alertBody = [NSString stringWithFormat:@"today is  : %@  \n event : %@  \n" ,date , events.text];



    [self createEvents];
    [self retriveData];


    notification.alertAction = @"View";
    notification.soundName = @"webcam_on.aif";





    NSUserDefaults *notificationDefaults = [NSUserDefaults standardUserDefaults];
    BOOL DAILYNOTIF = [notificationDefaults boolForKey:@"dn"];

    if (DAILYNOTIF == YES) {

        NSLog(@"DN is Active");

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];}


}

1 个答案:

答案 0 :(得分:1)

如果您想创建每日通知,为什么要将间隔设置为每年?

尝试更改此

notification.repeatInterval= NSYearCalendarUnit; 

通过

notification.repeatInterval= NSDayCalendarUnit;