2

If somebody can find a correct duplicate please link it to me I would greatly appreciate it however my situation is a bit different than those who also had the error. My specific issue is that once the simulator opens my app there is just a blank black screen, no errors occur or nothing loads until I tap the screen which results in the following error.

EDIT: I have commented out everything within my code and it still receives this error, as well as have created a new main.storyboard, still no solution...

unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: <UIClassicWindow: 0x7f9f3a445190; frame = (0 0; 414 736); userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x7f9f3a510ed0>; layer = <UIWindowLayer: 0x7f9f3a4077d0>>

I did not change any of my code as far as I can recall so below is my entire view controller followed by my app delegate

view controller:

import UIKit
import GoogleMaps
import Parse
import MediaPlayer
import MobileCoreServices


class ViewController: UIViewController {
@IBOutlet weak var viewMap: GMSMapView!



override func viewDidLoad() {
    super.viewDidLoad()

    let testObject = PFObject(className: "TestObject")
    testObject["foo"] = "bar"
    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        print("Object has been saved.")
    }

    let camera = GMSCameraPosition.cameraWithLatitude(33.600727, longitude: -117.900840, zoom: 16.9)


    viewMap.camera = camera
    viewMap.myLocationEnabled = true
    viewMap.settings.myLocationButton = true


    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(33.600727, -117.900840)
    marker.title = "Newport Beach"
    marker.snippet = "California"
    marker.map = viewMap

    // Do any additional setup after loading the view, typically from a nib.
    let button   = UIButton(type: UIButtonType.System) as UIButton
    button.frame = CGRectMake(100, 100, 100, 50)
    button.setTitle("Test Button", forState: UIControlState.Normal)
    button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(button)
    Upload()
}



func Upload() {
var path = NSBundle.mainBundle().pathForResource("/Users/matthewcarlson/Downloads/big_buck_bunny_720p_2mb.mp4", ofType: "mp4")
var videodata: NSData?
videodata = NSData.dataWithContentsOfMappedFile(path!) as? NSData


let file = PFFile(name:"resume.txt", data:videodata!)
file!.saveInBackground()

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func snapNext(sender: AnyObject) {
    let newLocation = GMSCameraPosition.cameraWithLatitude(33.622578, longitude: -117.911099, zoom: 16.9)
    viewMap.camera = newLocation



}

func buttonAction(sender:UIButton!)
{
    print("Button tapped")

}
}

AppDelegate:

import UIKit
import GoogleMaps
import Parse
import Bolts

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    // Initialize Parse.
    let configuration = ParseClientConfiguration {
        $0.applicationId = "w4hfIKBxy5uHc9eHQ3GavJ4vT9qyJBzKoO66pyM5"
        $0.clientKey = "jsZ8pfx6FfIVMlLUYvZ6MAdnBIltMiae5TgZWW9o"
        $0.server = "https://parseapi.back4app.com/"
    }
    Parse.initializeWithConfiguration(configuration)

    //initialize GoogleMaps
    GMSServices.provideAPIKey("AIzaSyDClpTwyY3swY2rlLKejd1pCVurTkVuNGg")
    return true



}

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Any help is greatly appreciate I have already cleaned the build, ran it again, and force quit Xcode and the simulator nothing has worked so far.

maz
  • 349
  • 2
  • 3
  • 15
  • I have a blank main.storyboard, app delegate, and view controller and this error is still occurring, any help is appreciated. – maz May 23 '16 at 02:39

3 Answers3

0

Try the following workarounds:

  • Set your status bar orientation before instantiating the UIWindow.

    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Init my stuff
        // ...
        // Prepare window
    [application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; // prevent start orientation bug
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    return YES;
    
  • Set "hidden" to YES for the window in my main xib.

  • Set the frame after the window get its orientation from root view controller.
  • Open the main xib file and find "Window" from the left side and enable Visible at Launch and Full Screen at launch.
  • Check out your Window nib file and make sure it is taking up the full screen.

Check these related questions:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • could you please edit that code to be in swift I never learned objective C – maz May 23 '16 at 21:09
  • Check these links: http://stackoverflow.com/questions/26916009/ios-8-uiwindow-orientation-is-always-portrait and https://recalll.co/app/?q=ios%20-%20UIWindow%20with%20wrong%20size%20when%20using%20landscape%20orientation – abielita May 24 '16 at 06:21
0

I was having this problem (_windows was always left being set to nil in my app delegate and I got a blank screen) and what I'd got wrong was I hadn't gone to the Target settings of my app and set "Main Interface" to the name of my starting storyboard

Sean O'Connor
  • 201
  • 1
  • 5
-2

Change the code. Add super.viewDidLoad at the last of the function not at the first it may solve your problem.

Dhruv Khatri
  • 803
  • 6
  • 15