gpt4 book ai didi

iphone - 每日 UILocaleNotification 的问题

转载 作者:行者123 更新时间:2023-11-29 04:45:22 25 4
gpt4 key购买 nike

我创建了一个通知系统,每天在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com