Welcome to the Treehouse Community
Looking to learn something new?
Lee Watkins11,345 Points
Calling a function in the "distant future"
I'm trying to find a way to get my code to execute a function in the "distant future" and looking for some help.
By distant future, I mean longer than an app may live in the background (3 minutes in iOS 7.1.1 I think.) So, say in 1 hour's time.
Is there a way that I can tell my app to wake up and do something in 1 hour from now?
I know of:
- dispatch_after, and
- scheduling local notifications
but will any of these work, and how would one implement them? And what happens to said action if my app crashes in the background for some reason?
I think local notification would be great (because I would like to notify the user in some cases,) but the problem comes in (I think) if the user doesn't launch the app when the notification is presented.
Rodrigo Chousal16,009 Points
Have you considered sleep()? You write the number of seconds you want the program to stop running in between the parenthesis.