You have 2 problems in the code. At first, the sequence of startup functions (the so-called execution states) seems incomprehensible to you, and secondly, you added a listener to the updateSettings function, but you never called it in the code above, and thatβs why nothing changed when your application started.
Let me explain the initial sequence first. When the application is loaded from a turned off device, these states are triggered:
application:didFinishLaunchingWithOptions: applicationDidBecomeActive:
After that, if you click the "Home" button, these states will be launched:
applicationWillResignActive: applicationDidEnterBackground:
Then, if you re-enter the application, the following will happen:
applicationWillEnterForeground: applicationDidBecomeActive:
Please note that the download status occurs only once at the first boot (but not after returning from a home press). Now, for each view, the viewDidLoad function will only call one time that was first called by that view. If you call this view again (after loading it), the viewWillAppear function will be called viewWillAppear . Therefore, usually updating occurs in viewWillAppear .
The important thing that I noticed in your code is inappropriate is to use the basic functions of a delegate. In applicationWillEnterForeground you manually call viewDidLoad until you have to do this, as this function will be called automatically, as I explained above. I also see that you are adding Notification centers that are not needed.
Now consider the second problem in your code. You add the Notification Center for the updateSettings function to viewDidLoad . Well, loading this view will happen after the UIApplicationDidFinishLaunchingNotification event, so in practice you never called the updateSettings function. Moreover, since this function is a member of your class, you do not need a notification center to call it. We usually use the Notification Center when we need to call a function from another class. Just what you need to do is call this function directly from viewDidLoad as follows:
[self updateSettings]
And if you need to update after pressing the home button, call the function from viewWillAppear .
Hope this quick explanation helps you.
EDIT: answer your comment below
If you have only one view (no navigation controllers ...), after its appearance for the first time, it will remain in memory and it will not appear anymore (so this function is not called). Here you should catch the UIApplicationDidBecomeActiveNotification event to do the following:
In viewDidLoad add a notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSettings) name:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication]];
This will allow you to call the updateSettings function every time your application wakes up. Also remember to remove this listener at the end:
[[NSNotificationCenter defaultCenter] removeObserver:self];