Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Mac Catalyst apps handle lifecycle transitions?

Is it just my app, or do all Mac apps made with Catalyst not undergo lifecycle changes except when launching or quitting?

Upon launch, the UIWindowSceneDelegate methods sceneWillEnterForeground: and sceneDidBecomeActive: are called. When quitting sceneWillResignActive and sceneDidEnterBackground are called.

But these never take place when the app is left open and I change to a new app, or let my computer sleep, or do other normal human usage patterns that I would expect to force the app into the background state. I'm left with the impression that the app never leaves the foreground state as long as it is not quit by the user. Is this correct?

If I implement support for automatic or sudden termination (as detailed here), might the app enter/exit app states more frequently?

Is there something I am misunderstanding?

Thank you for any help.

(Note: I built a system that logs app transitions – rather 'scene' transitions – so as to be able to test without running the app in Xcode.)

like image 422
AVS Avatar asked Jan 28 '20 23:01

AVS


1 Answers

In my case, a workaround helped:

#if targetEnvironment(macCatalyst)
   nc.addObserver(self, selector: #selector(hold), name: NSNotification.Name("NSApplicationDidResignActiveNotification"),object: nil)
   nc.addObserver(self, selector: #selector(resume), name: NSNotification.Name("NSApplicationDidBecomeActiveNotification"),object: nil)
#endif

Hopefully in the future there will be a more elegant option using UIScene.

like image 142
Jury Shortki Avatar answered Oct 01 '22 03:10

Jury Shortki