I am making an iPhone app, which has a requirement of Local Notifications.
In local notifications there is repeatInterval property where we can put the unit repeat intervals for mintute, hour, day,week,year, etc.
I want that repeat interval should be 4 hours.
So every 4 hours the local notification comes.
I dont want the user to set seperate notifications for each.
I want the user to be able to set repeatInterval as 4 hours.
How do I do that?
I have one idea how to do this, i've implemented this in my project
First, create local notification with fire date (for example, every minute). Next step - fill user info with unique id for this notification (if you want to remove it in future) and your custom period like this:
After that, implement
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
in your AppDelegate:Just add it into the sheluded notificatiots again!
if you want to remove this notification, do
Very important!
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
do not called, when you at background. So, you must setup long-running background task, where you will create notification again.You can set any time interval you want, if you set up separate notifications for each time you want a notification to fire. You then have to manage them, and if you are not an app that is at present allowed to run in the background, you'll have to refresh them by having the user run your app to do so. Having accomplished this, I can tell you it is a major PITA.
The repeat interval is just an enum that has a bit-map constant, so there is no way to have custom
repeatIntervals
, just every minute, every second, every week, etc.That being said, there is no reason your user should have to set each one. If you let them set two values in your user interface, something like "
Frequency unit: Yearly/Monthly/Weekly/Hourly
" and "Every ____ years/months/weeks/hours
" then you can automatically generate the appropriate notifications by setting the appropriate fire date without a repeat.i have used this code and it is working fine for repeat LocalNotification i have used LavaSlider Code for this code implemetation
notif.repeatInterval = NSDayCalendarUnit;
Got the answer
It is as straight as it gets.
You cannot create custom repeat intervals.
You have to use on NSCalendarUnit's in-built Unit Time Intervals.
I tried all the above solutions and even tried other stuffs, but neither of them worked.
I have invested ample time in finding out that there is no way we can get it to work for custom time intervals.
Hope this helps all who are looking out for the solution.
Thanks to all the guys who tried to answer my question. Thanks Guys!!