iphone - 每日 UILocaleNotification 的问题

标签 iphone objective-c ios xcode ipad

我创建了一个通知系统,每天在12:02 AM推送通知,但我不知道我的代码是否有效,并且从应用程序推送通知仅持续一两天!你能帮我找出问题所在吗?

- (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];}


}

最佳答案

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

尝试改变这个

notification.repeatInterval= NSYearCalendarUnit; 

notification.repeatInterval= NSDayCalendarUnit; 

关于iphone - 每日 UILocaleNotification 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9734135/

相关文章:

objective-c - 动画 UITextView

ios - 没有模型无法解析json

ios - 在开关 block 中使用 objectAtIndex 方法

ios - applicationDidBecomeActive 根本没有被调用

iphone - 为什么我的音频没有按时播放?

iphone - 在iPhone中使用FFMPEG音频转换

iphone - tableheaderview 滚动事件

xcode - 关于bringSubviewToFront

iphone - 硬盘重新格式化 : Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain

iphone - 列出 Google 云端硬盘中的所有文件夹内容