Application error due to auto lock in iphone?

My application crashes due to the fact that the automatic blocking time is 2 minutes, and my web serevice takes longer than 2 minutes. if time passes more than 2 minutes, my application crashes every time.

but I don’t want to set the auto-lock time to 15 minutes or never set it. I want some solution in the application without changing the setting value.

please let me know if anyone knows a solution to avoid an accident.

Thanks.

0
source share
2 answers

You can temporarily disable automatic locking until the request is completed and set [UIApplication sharedApplication].idleTimerDisabled to YES .

Another option is to set the web service request as the final task running in the background , so even if your device goes to sleep, the request continues to work. Beware of the 10 minute time limit.

In any case, when starting in the foreground, make sure the request is executed asynchronously and does not block the main thread, or your application will always be killed after that for too long.

+3
source

How to find out when your app goes to background / inactive

- (void)applicationWillResignActive:(UIApplication *)application

and use the task completion mechanism - look at this question: How to implement task completion

As a side note for completing the background task, there is a limit of 10 minutes (you get a warning) - otherwise your application will be terminated.

Have you considered breaking the data into smaller pieces and tracking the progress?

+1
source

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


All Articles