uiapplication
UIApplication sharedApplication – keyWindow is nil?
This code was executed before [window makeKeyAndVisible]; which is inside the app delegate. So, no wonder why keyWindow was nil yet.
Get Application’s main window
The UIApplicationDelegate usually has a reference to the “main window”: [[[UIApplication sharedApplication] delegate] window]; Furthermore, UIApplication has an array of windows [[UIApplication sharedApplication] windows]. See the UIApplication Class Reference.
What is the difference between UIApplication.sharedApplication.delegate.window and UIApplication.sharedApplication.keyWindow?
For most uses, they will be the sameā¦ but not always. [UIApplication sharedApplication].keyWindow is the window which is currently being displayed on the device. This is normally your application’s window, but could be a system window. [UIApplication sharedApplication].delegate.window is the window your application is expected to use. Which one should be used? Well that all … Read more
Getting a reference to the UIApplication delegate
Yes, UIApplication is a singleton, and uses the normal singleton pattern for Objective-C: [UIApplication sharedApplication]; You can get your delegate class directly from it: MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
how to get my UIWindow using UIApplication?
If your main window is an outlet of your AppDelegate (which should be the case), you may simply use MyAppDelegate* myDelegate = (((MyAppDelegate*) [UIApplication sharedApplication].delegate)); [myDelegate.window …]
How to get the actual [UIScreen mainScreen] frame size?
Actually that is very usefull. When you ask a UIScreen for it’s Bounds you get the bounds of the screen, which is the whole device screen. (the status bar is part of the screen) But if you ask a UIScreen to tell you where and how big can be the root view of your application … Read more
-[UIApplication delegate] must be called from main thread only
Just call it from the main thread like this. Objective-C dispatch_async(dispatch_get_main_queue(), ^{ [[UIApplication delegate] fooBar]; }); Swift DispatchQueue.main.async { YourUIControlMethod() } Reaching out to your app delegate like this, is a hint that your architecture could use a little cleanup. You can call delegates from any thread you want. You only need to make sure … Read more
Adding view on StatusBar in iPhone
You can easily accomplish this by creating your own window above the existing status bar. Just create a simple subclass of UIWindow with the following override of initWithFrame: @interface ACStatusBarOverlayWindow : UIWindow { } @end @implementation ACStatusBarOverlayWindow – (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Place the window on the correct level and … Read more