in my app I have a UIProgressView that needs increase by +0.1 every 5 minutes. The method for doing this, but I know I have a problem, because I would like the calculations progressview five minutes even if my application is then closed should rely on real-time (iphone clock) and not that when my application is open ... I'll explain
I know that to do that I should use NSDate but can not implement it in the right way, could someone help me with an example to better understand how to implement this?
Thank you all
in a few words what I look for is that the increase uiprogressview must be obtained from the clock iphone minutes ... this has to happen is if the app is open or closed .... just one more minute comes uiprogressview must change. .. in short, this should be a recover energy from a user
I think you should:
NSDate *startDate = [NSDate new];
save actual start date to NSUserDefaults:
[[NSUserDefaults standardDefaults] setObject: startDate forKey: @"MyKey"];
NSTimeInterval secondsBetween = [[NSDate new] timeIntervalSinceDate: savedDate];
ViewWillAppear
):progress = secondsBetween/(5*60) * 0.1
If you want to refresh your progress after each time unit when your ViewController is active you should use NSTimer:
[NSTimer scheduledTimerWithTimeInterval: (5 * 60)
target:self
selector:@selector(refreshProgressMethod)
userInfo:nil
repeats:YES];