Reputation: 31637
Below is the code I am using to send local push.
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
NSString *alertText = [NSString stringWithFormat:@"Test Push Title"];
localNotification.alertBody = alertText;
localNotification.soundName = @"Glass.caf";
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
But now I want to send push from to date with interval of hours.
E.g. I want to send push from 1-Jan-2014 to 2-Feb-2014.
Now daily I will have 3 push. Each push will start at 8 pm and in a day after 6 after I will get rest push. Means first push at 8am, second at 2pm and 3rd push at 8 pm.
Any idea how to do this?
Any guidance would be greatly appreciated.
Actually I want to do the reminder where I will have below inputs.
Daily how many times you will have medicine
From what time you will have medicine
After how many interval you will have another medicine
For how long days you will have medicine
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
NSTimeInterval interval = 1*60;
for (int i =0;i<=2;i++ ) {
// setup the notification using the fire date
// pickerDate = [pickerDate dateByAddingTimeInterval:interval];
pickerDate = [pickerDate dateByAddingTimeInterval:interval];
}
I tried with this code, but still I am getting one push. I was expecting 4 pushes...
Upvotes: 0
Views: 138
Reputation: 119031
You can have up to 64 scheduled notification so be aware that there is a limit.
You can put your above code into a loop and add the interval date components (using a calendar) or the interval seconds (dateByAddingTimeInterval
) onto the fire date of the previous notification.
Aside, this is pointless:
[NSString stringWithFormat:@"Test Push Title"]
And wasteful. There is no format, it's just a string so just directly use @"Test Push Title"
.
NSDate *fireDate = pickerDate;
NSTimeInterval interval = ...;
for ( however you decide how many notifications there are ) {
// setup the notification using the fire date
fireDate = [fireDate dateByAddingTimeInterval:interval];
}
Upvotes: 1