How can I determine what controller/window is currently in the applicationDidBecomeActive? For example on the login screen (which is a LoginViewController), if the applicationDidBecomeActive fires how do I know it is the login screen from the appDelegate?
Asked
Active
Viewed 930 times
1 Answers
3
The UIApplication
object passed to applicationDidBecomeActive
has a windows
property. It is an NSArray
of visible windows, ordered back to front.
Once you have the foreground window, you can get the first subview and test its type:
if ([[foregroundWindow.subviews objectAtIndex:0] class] == [LoginViewController.view class]) {
...
}

highlycaffeinated
- 19,729
- 9
- 60
- 91
-
thanks i can access this and just seeing what is in the subview. I'm trying to iterate through the window.subviews but how do you determine what each subview is? I'm not sure if there is a method in objective-c which compares type? e.g. if([window.subviews objectAtIndex:0] == "LoginViewController") I had a look at the class reference but can't see if i can access a name type but I see a viewDelegate but I don't know how to retrieve it. – fes Jul 12 '11 at 18:01
-
the class name at objectAtIndex is always UIView. In my didFinishLaunchingWithOptions I have [window addSubview:loginViewController.view]. So at objectAtIndex its UIView which is true, as the loginViewController extends UIViewController which extends UIView. It feels as though I might need a parent parent of this UIView if that exists. – fes Jul 12 '11 at 18:22
-
Hmmm. Instead of comparing the classes, you could compare the references and see if they are the same object: `[foregroundWindow.subviews objectAtIndex:0] == LoginViewController.view` – highlycaffeinated Jul 12 '11 at 19:06
-
that works i can see the UIVIew: 0x[hex_here] is the same so its true. so you might need to update your answer. – fes Jul 12 '11 at 19:17