[iOS] Foce quit, then reopen => 10 seconds freeze, then app restarts
Hello I encountered this strange behaviour that happens only on iOS.
1. Open game
2. At any point force close it (Swipe up where all the last opened apps are shown, then swipe up on my app to remove it from the list)
3. Then re-enter the game
Expected: The game should relaunch normally, starting from the splash screen
Actual: I see the last frame before I paused the app before force quitting for about 10 seconds. I think the game settles some undone tasks from the last session, but I cannot be sure.
Then the game acts normally and starts from the splash screen.
Extra info: If I install from TestFlight, when re-entering the app, it crashes. There is another scenario. If I just force close the app, then wait 10 seconds, I get a crash. Again, this only happens with TestFlight. It is very similar to this: https://answers.unity.com/questions/1722813/unity-20192-ios-build-crashes-5-seconds-after-the.html Anyway, the workaround with the post build script does not work.
Noteworthy plugins I am using:
Admob (but the problem happened before installing it)
Sprite Skin + Animation 2D (these has caused me many problems, but problem happens even if I force quit in scenes where I don't use it)
This is what I get when quitting: That Enlighten thread might be the culprit, but I have already disable everything light related.
-> applicationDidEnterBackground()
-> applicationWillTerminate()
Quitting
MainScreenManager:OnApplicationQuit()
Setting up 1 worker threads for Enlighten.
Thread -> id: 16cbcb000 -> priority: 1
Message from debugger: Terminated due to signal 9
My main questions would be:
1. Why does the app hang on the last frame, even if it has been closed manually by the user?
2. I am not making any web calls in OnApplicationPause. What else could make the app execute some work to be done after force quitting? Already checked my own OnApplicationPause and OnApplicationFocus and they do trivial stuff like removing listeners from a list.
3. I have a threading solution that waits for tasks in an infinite loop on a separate thread. While it has nothing to execute, I do a Monitor.Wait(tasks) inside the infinite loop, so the thread actually sleeps. Could this cause any problems?
Thanks for reading
Answer by silviu-georgian77 · Aug 30, 2021 at 07:58 PM
Found the problem. It had to do with a couple of worker threads that I was spawning. In C# we have Thread.IsBackground which I had to set to true. If it is false, the system thinks that they are foreground threads and will wait until they complete. The iOS system gives them about 10 seconds to complete after you force close the app. If you set Thread.IsBackground to true, the app closes immediately.
Your answer
Follow this Question
Related Questions
Restart the application 0 Answers
Application.Quit() won't work on iOS and screen does not auto lock while inactive 0 Answers
Android app load delay after quitting application 0 Answers
Screen orientation on ios in multitasking menu becomes portrait upside down 0 Answers
Workflow for developing Unity with native UI (Android and iOS) 0 Answers