ejaz dogar
ejaz dogar

Reputation: 115

Calling a method at a particular time of the day in iOS

I am developing an application in which there is this scenario in which I have to make a database entry for a new day each time date changes i.e. time become 00:00 or 12:00 am. I have a method which is responsible to do this but I don't know and can't even find a way to call it when the date changes or when the time turns 00:00. Kindly, help me out if you know any link or if you have any suggestion to do this.

Upvotes: 0

Views: 380

Answers (1)

Ravi_Parmar
Ravi_Parmar

Reputation: 12329

Don't have the exact code but I think this can help you :

First of all without background support your app can't make a service call :

Learn about background task here : Background fetch tutorial

Now you can do one thing, get the current time whenever the app launches and find the time till next midnight, then start a timer to fire after that time interval. Hope this helps.

Like this :

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(updateNewDate) userInfo:nil repeats:YES];

Here you need to make timeInterval dynamic in accordance to the current time and midnight difference.

Upvotes: 1

Related Questions