Managing Your App’s Life Cycle

Sayler8182
Mac O’Clock
Published in
Sep 4, 2020

--

As we all know iOS app can be in different states depends on user activity. Is easy to manage it and observe changes in AppDelegate but UIViewController (or any other object) doesn’t have this callbacks by default.

We can change it!

At the beginning we need to know what event can we observe. I’ve already done the research and found all available options.

Now we should define base protocol that shows us what we can do with our ‘manager’. It’s good practice to always define protocols for such things. We need information about which events object should be informed and how to behave when action occurs.

Now it’s time to implement core of our code

Ok, we have all required parts, now we can use our manager. It’s very important to properly register and unregister notifications.

From now on our view controller will receive all registered events! You can do the same for all your objects.

TL;DR

Using AppLifecycle helps us notify object about app state changes Read it! Is worth it ;)

Thank you for reading! If you liked this article, please clap so other people can read it too. I will also have more motivation for the next article :) You can also see my other articles, maybe you will find something for you.

If you have any question or suggestion leave a comment.

--

--