How to : Debug UIWindows were created prior to initial application activation - ios

My console posted this error today, [ApplicationLifecycle] UIWindows were created prior to initial application activation. This may result in incorrect visual appearance.
This has caused Application UI to not behave properly. I have never seen this before and need some insight on where to start debugging.
macOS: Catalina 10.15
XCode version: Version 11.1

I think that apps main UIWindow should be lazily initiated. Try with this:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var window: UIWindow? = UIWindow(frame: UIScreen.main.bounds)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window?.rootViewController = RootViewController() // root view controller
window?.makeKeyAndVisible()
return true
}
}

Related

UIApplication delegate must be used from main thread only

I have a standard AppDelegate file in my Xcode project, I'm experimenting with Firebase and as soon as I imported it & added
FirebaseApp.configure()
I was flagged with purple warnings: Click me
The whole AppDelegate looks as follows
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
These warnings never appeared whilst using Xcode 8, as a novice I am unsure on how to fix this, I have read that adding a DispatchQueue.main.async can fix it but I'm not sure where to add this.
Thanks!

App crashes with message "Usage: leveldbutil command..."

I'm using Swift 3 and XCode 8.3.3.
My app crashes before starting, it prints :
Usage: leveldbutil command...
dump files... -- dump contents of specified files
Then it crashes I didn't find any solution for this issue.
check your AppDelegate and find #UIApplicationMain
this statement if this is not available then put in just above the class like this
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Try cleaning the project and retry.

Firebase: FIRApp.configure() keeps wanting me to change it to FirebaseApp.configure()

So I made a project that included lots of extra code so I could try out different things, and I am slowly copy-pasting the files from textedit into my new project.
I created a new Firebase account, added the google plist file, initialized and installed the pods needed (also changed the iOS version to 10.0 on the pod file)... yet it's still wanting me to use FirebaseApp.configure() instead of FIRApp.configure().
Should I just delete the whole thing and try again? I just created a new Xcode project, so if I had to delete it right now that would be fine.
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
override init() {
super.init()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
return true
}
There hasn't been much code written, but I can't figure out what could have made this happen... especially since I just started the new project.
FirebaseApp.configure() is correct. I checked out the documentation just now and FIRApp.configure() has been renamed FirebaseApp.configure(). I also ran pod update on one of my projects just to confirm, and my project had me change to using FirebaseApp.configure(). So no need to rebuild!
I can confirm that FIRApp.configure() can be changed to FirebaseApp.configure()
In firebase it suggest to add the following to app delegate:
"
import UIKit import Firebase
#UIApplicationMain class AppDelegate: UIResponder,
UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)
-> Bool {
FirebaseApp.configure()
return true } }
"
This includes the FirebaseApp.configure() command

Manually Created UIWindow is Wrong Size

I am learning how to create an iOS app without Interface Builder (i.e. storyboards, xibs, etc.). Below is the basic app delegate class I am working with. The problem is that when displayed the UIWindow does not use up the full screen of the device (see attached screenshot). This occurs on all the devices and simulators I test with. Why isn't the fullscreen being used?
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var window: UIWindow? = {
debugPrint("AppDelegate: Creating Window")
let screen: UIScreen = UIScreen.mainScreen()
let window: UIWindow = UIWindow.init(frame: screen.bounds)
window.backgroundColor = UIColor.whiteColor()
return window
}()
lazy var rootViewController: ShapesViewController = {
debugPrint("AppDelegate: Creating Root View Controller")
let rootViewController = ShapesViewController.init(nibName: nil, bundle: nil)
return rootViewController
}()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
debugPrint("AppDelegate: applicationWillEnterForeground")
window?.rootViewController = rootViewController
window?.makeKeyAndVisible()
return true
}
}
The problem turned out to be that I did not have a launch image or storyboard. For some reason without this the app defaults to the 3.5" size. Credit to this comment: A launch storyboard or xib must be provided unless the app requires full screen
This always works for me (I don't see any clear difference though). Do you mind sharing your ShapesViewController code as well?
Updated to swift 4.2
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
return true
}
I know sounds silly but...
For a fresh project what macinjosh is saying works.
For a project of mine in Xcode 8 and swift 3, it didn't (probably because I deleted the launch screen and had to create again).
Just created new project fresh, and follow what macinjosh said. Then migrate all your files back in.

How to create an empty ios project in xcode 6?

i'm using xcode 6 and they no longer have the "empty project" option when creating a new project, only a single view one...Is there an option to get it or it's gone and I need to deal with it?
Thanks a bunch
You need to deal with it, but it's easy. Start with the Single View application. Delete the storyboard and delete the reference to it in the Info.plist (so that there is no longer a main storyboard). If you like, delete the view controller class as well. Now just do everything from scratch in the app delegate's application:didFinishLaunchingWithOption:, just as you did in Xcode 5.
I'm using Swift these days, so I'll show you what a pure code app delegate launch looks like in Swift; I'm sure you can translate into Objective-C:
import UIKit
#UIApplicationMain
class AppDelegate : UIResponder, UIApplicationDelegate {
var window : UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
self.window!.rootViewController = ViewController() // or whatever you call it
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
return true
}
}

Resources