I don't see where your sample code attempts to present the modal view controller. Perhaps it happens inside of -[ZTCAPIClient login]
.
Generally speaking, you can't present a modal view controller until after the presenting view controller's view is in the view hierarchy. For your specific question, this means your program needs to present the modal sometime after the line that reads [self.window makeKeyAndVisible];
. It will not work if your program tries to present the modal view controller before, in fact, you'll probably see an error message logged to the debug console.
On a side note, you should be careful not to make your program do too much in -application:didFinishLaunchingWithOptions:
. If your program takes too long, the system may kill your app the iOS App Programming Guide states:
Your application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods should always be as lightweight as possible to reduce your app’s launch time. Apps are expected to launch and initialize themselves and start handling events in less than 5 seconds. If an app does not finish its launch cycle in a timely manner, the system kills it for being unresponsive. Thus, any tasks that might slow down your launch (such as accessing the network) should be executed asynchronously on a secondary thread.
When launching into the foreground, the system also calls the applicationDidBecomeActive: method to finish the transition to the foreground. Because this method is called both at launch time and when transitioning from the background, use it to perform any tasks that are common to the two transitions.