I am trying to fire a local notification every day on 12:01 AM , but I don’t know why my code does not work. Would you please help me to find the problem?
local = [[UILocalNotification alloc]init];
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSPersianCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
//edited:
[dateComps setYear:1390]; //2012
[dateComps setMonth:10]; //1
[dateComps setDay:9]; //29
local.repeatInterval = 5;
[dateComps setHour:00];
[dateComps setMinute:1];
[dateComps setSecond:00];
local.fireDate = [calendar dateFromComponents:dateComps];
local.alertBody = @"HELLO";
local.alertAction = @"View";
local.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication]scheduleLocalNotification:local];
You’re not setting the notification’s
repeatIntervalproperty and your date components are missing a month, year and day. The defaults are zero, so yourfireDateis way back in the past.Also, you might want to be using
NSGregorianCalendarinstead ofNSPersianCalendar.