I have created a notification system which push notification everyday at 12:02 AM but I don’t know my code works and push notifications from app just for one or two days !! would you please help me to find the problem ?
- (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];}
}
If you want to create a daily notification why have you set the interval to yearly?
Try changing this
by