How to update the application every 24 hours in the lens c

I want to update my local database using the current server through a web service. I know how to send a request to a server and analyze the output of a web service. The problem is that I want this update to happen every 24 hours, regardless of whether the application is open or closed. I just want to know if this can be done or not. If possible, someone will tell me how to do this.

Thank you very much in advance

+4
source share
4 answers

This can only be done when your application is open (Foreground) using UILocalNotifications , which you can use to trigger an event after a duration, and you can update your database.

But if the application is not open, you cannot make changes to the database. because the apple does not allow changes to the database when the application is inactive.

Check this link: What type of services can I use if the application is in the background?

+3
source
  • Create a column for the timestamp in your webservice DB.

  • When you first start inside - (void)applicationWillEnterForeground:(UIApplication *)application in appDelegate , get the timestamp from the server and save it in a local DB/Plist , etc.

  • Put the condition in - (void)applicationWillEnterForeground:(UIApplication *)application , and when the application reappears in the foreground, check if local timestamp and server timestamp 24 hours , start updating local DB with server updating, again save the timestamp from server to local for the next 24 hours.

Has the meaning? The update will only start when application moves to foreGround . Thus, you can update local DB not only 24 hours, but at any time.

Another easy way is to create a file (any empty file) locally when application comes to foreGround . And when application reaches foreGround the next time, check if there is more than 24 hours of creation time this file. If so, take data from the server and overwrite file . Thus, you cannot send a signal from the server to update the local application DB.

+2
source

You cannot do this in the background because the apple does not allow this.

You can do this when your application is open.

The first time you update the database, you can save your timestamp in NSUserDefaults, and then the next time your application is open, the current timestamp is longer (24 hours) than your previous timestamp (which is stored in NSUserDefaults), and then it updates your database and update the timestamp in NSUserDefaults.

0
source

Nope. Apple will not allow this.

This must be done in order to try to save the update, there is no sure way that the user will upload your things, that the application will be stored in the foreground, that its 3G coverage is good (looking at you, T-Mobile), etc.

If you are dealing with static content that needs to be updated from time to time, then save the last date that you updated on the device ( NSUserDefaults comes to mind), and when the user starts the application, ask the server "Hello brother, last time I updated, it was NSDate , do you have anything for me? " Then perform the appropriate update.

0
source

Source: https://habr.com/ru/post/1492233/


All Articles