0

I need to execute a function when app is in the background or even when is killed by the user, automatically based on time Intervals

Requirement: After user registered (Ex registered date Jan-1, 2015) , I need to change the status of a functionality as enable/disable based on following time intervals and notify user when app is in active mode or in background or it is killed.

Registered date Jan-1, 2015: View photos functionality status is changed as follows. When status has enabled Mode user can able to see photos by taping on photos row in a table. When status is in Disable Mode user can not able to see photos and generate an alert by taping on photos row in a table.

First 2Weeks: Disable 2Weeks - 5th Week : Enable 5th Week - 12th Week : Disable 12th Week - 3months : Enable 3months-8months : Disable 8months-12months : Enable 1Year - 1.5Year: Disable 1.5Year- 2Years Enable After 2 Years - Status switches between every 3 months.

I am done with the Dates calculations.

But i just want to know how to execute a function when app is in the background or even when is killed by the user, automatically based on time Intervals

THanks in advance

Apurv
  • 17,116
  • 8
  • 51
  • 67
iOS dev
  • 2,254
  • 6
  • 33
  • 56
  • So you have no clues whatsoever how to solve this issue? – trojanfoe Dec 04 '15 at 08:04
  • Ask yourself: how can an app that isn't running execute a function? When you've solved this Zen riddle, you will be ready for the next step. – Avi Dec 04 '15 at 10:03

2 Answers2

1

I think that the way you choose is wrong. Just use the AppDelegate methods to know when the app is launched or when the app will come back in foreground status.

UIApplicationDelegate Apple Reference

Luca D'Alberti
  • 4,749
  • 3
  • 25
  • 45
0

You can call function in Background it's possible but app kill then function not work. Try this code for Background work.

- (void)applicationDidEnterBackground:(UIApplication *)application {

[NSTimer scheduledTimerWithTimeInterval:300.0f
                                 target:self
                               selector:@selector(updateMethod:)
                               userInfo:nil
                                repeats:YES];

}

- (void)updateMethod:(NSTimer *)theTimer {
// Your code goes here
NSLog(@"Backgroud Mode");
}
bhadresh
  • 445
  • 5
  • 15