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