122

I'm having trouble running my basic iPhone application (while going through the Stanford iTunes CS193p lectures) in the iOS simulator.

I've been searching for a while (both Google and SO), but unable to find a solution so far. There are many similar bugs, but the solutions don't seem to fix this.

In Xcode I click "run". It compiles and builds successfully, launches iOS simulator but it never gets to loading the app. Only the status bar at the top. With a black screen.

I've only written very basic code (following along with the lectures) and can't get past this problem.

To confuse matters more, I wrote a web wrapper (UIWebView) before these lectures and this works fine. But there is barely any difference in the code. All new apps I create from scratch all fail with the same black screen problem.

If I hit the home button on the simulator and launch the app, it will display. But Xcode doesn't seem to know what's going on.

It's as if Xcode has lost the ability to talk to iOS Simulator and assumes it's running (even if I quit iOS simulator). I try and quit Xcode, and it asks me to stop the tasks. Then it just hangs. So I have to force restart to get out of Xcode.

I'm using: OSX 10.8.2 Xcode 4.5.2 iOS Simulator 6.0

CalculatorAppDelegate.h

#import <UIKit/UIKit.h>

@interface CalculatorAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

CalculatorAppDelegate.m

#import "CalculatorAppDelegate.h"

@implementation CalculatorAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// 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.
}

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

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 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.
}

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

@end

CalculatorViewController.h

#import <UIKit/UIKit.h>

@interface CalculatorViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *display;

@end

CalculatorViewController.m

#import "CalculatorViewController.h"

@implementation CalculatorViewController

@synthesize display = _display;

- (IBAction)digitPressed:(UIButton *)sender
{
    NSString *digit = [sender currentTitle];
NSLog(@"digit pressed = %@", digit);
}

@end
Cœur
  • 37,241
  • 25
  • 195
  • 267
Matt
  • 1,473
  • 2
  • 11
  • 13
  • 1
    I get this sometimes. It is entirely unrelated to project code and is some bug or issue with XCode. It also happened in earlier versions (XCode 4.x). No solution but to force quit. – spring Feb 03 '13 at 01:21
  • 1
    Yep, I force quit, restart my computer, then startup Xcode. Also you might want to delete the "Derived Data" in the Xcode organizer (project section) – MCKapur Feb 03 '13 at 01:26
  • 3
    If your simulator doesn't fit your screen, you might be seeing the bottom of a basic tutorial app with a white background. By scrolling, rotating or scaling the window (command+3) you could find out. This might not be obvious for a beginner, thus it could help somebody. – DiegoG Oct 18 '15 at 09:05
  • for me its resolved by clearing stored cache [mentioned in here](https://stackoverflow.com/questions/72653527/ios-16-simulator-running-an-app-in-the-simulator-results-in-an-xpc-error) – abhish Apr 20 '23 at 02:31

36 Answers36

137

Surprisingly, what worked for me was going to iOS Simulator menu, and pressing "Reset Content and Settings". (in iOS 13, its under Hardware)

Community
  • 1
  • 1
doug
  • 1,963
  • 2
  • 16
  • 24
  • 18
    Jep, that did the trick for me! For those of you who couldn't find that option: Start the simulator and then choose in the menu bar (top of the screen) `iOS-Simulator -> Reset Content and Settings`. – Timo Ernst Aug 14 '13 at 13:30
  • Thanks that was really helpful guys! – Nizar B. Sep 02 '16 at 23:51
  • 19
    Didn't help me at all :(( – mimic Sep 20 '16 at 20:24
  • @mimic I am getting white-screen (not black screen). My app is the basic template with a TextBox and a label but I didn't see anything. I had to switch to iPhone 5 image and it finally worked. I also see that the text box is all the way across the view in design mode in xcode but it is squished to the right side of the form. Make sure your controls aren't just pushed off to the right or something. Just some ideas. – raddevus Sep 21 '16 at 01:24
  • 1
    @daylight Thanks for your comment. I noted that this problem exists only for one specific project, and because this project has been created just for testing purposes I don't care much. – mimic Sep 21 '16 at 18:50
  • 3
    @mimic try running `xcrun simctl shutdown all` – Rish Apr 04 '18 at 15:17
  • 1
    This setting is now under the "Device" menu bar – izhang05 Jun 22 '20 at 15:53
  • Worked for me..... -_- – Mike Bryant Oct 14 '21 at 05:18
  • or just from the Device menu, restart it . – Mehdi Chibani Feb 02 '22 at 13:49
  • 1
    Update: now it's called Erase All Content and Settings, you can find it in the upper simulator's options tab ---> Device – Sherif Samir Nov 14 '22 at 08:09
  • Didn't work for me. Restarting the simulator by closing it and running the app again did it for me. But I have to do this for every 10-11 app runs. – Deveesh Feb 21 '23 at 07:47
45

Before resetting the emulator first go to your projects "project navigator" screen and under the general -> depoyment info screen check that the main interface property is properly setup!

enter image description here

Chris
  • 4,593
  • 1
  • 33
  • 37
  • This worked for me! Though my problem was on the device. After the launch image, it just goes black with a status bar. Not even reaching applicationDidLaunchWithOptions at the appDelegate. – SleepNot Jan 27 '14 at 09:13
  • Im pretty new to ios to be honest, but it sounds like your app is throwing an exception on startup. Did it work correctly in the emulator? You can try running it via the emulator and have a look at your log, this should give you some indication what the exception is if it is the case – Chris Jan 27 '14 at 09:24
  • No it's okay now. Wasn't outputting any exception, I even tried logging. Your answer solved it for me. – SleepNot Jan 29 '14 at 01:54
  • Similar issue here. In the next section "App Icons and Launch Images" the "Launch Screen File" wasn't set. Once set I had my UI again. – Wizard of Kneup Apr 11 '15 at 20:17
  • I deleted my main storyboard and re-added it, which caucused the project setting "Main Interface" to be blank. Thanks a million! It fixed my mystery. – JIANG Feb 06 '18 at 17:32
17

If you're using SwiftUI

If you're updating from a previous version of Xcode 11, there are some changes to the SceneDelegate willConnectTo session: options connectionOptions initialization:

The main window is now initialized using UIWindow(windowScene: windowScene), where it use to be UIWindow(frame: UIScreen.main.bounds)

On previous version:

    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()

In new version:

    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: ContentView())
        self.window = window
        window.makeKeyAndVisible()
    }
bauerMusic
  • 5,470
  • 5
  • 38
  • 53
  • 1
    Thank you very much, given this is a relatively new technology. Finding this answer was a bit challenging, it was the answer to my solution ! – Yuliani Noriega Aug 07 '19 at 19:25
  • Thank you so much, i tried everything. This is so not obvious solution that thank you for sharing it. – Nalov Oct 09 '19 at 18:01
9

I am a newbie to the iOS app development. I was practising to develop iOS apps from the very beginning and while running a very basic Hello World app, I also faced same issue that only a black blank screen appears after building and running the app in iOS simulator. Somehow while struggling to find out a solution to the problem I accidentally clicked Window-->Scale-->50% in iOS simulator and it did solve my problem. I could then see the Home page with my app and clicking on app icon I was able to run my app successfully. App versions: Xcode 5.1 iOS Simulator: 7.1 OSX: 10.9.3

asdf
  • 91
  • 1
  • 5
7

Restarting your computer should be all you need to do.

Lolo
  • 3,935
  • 5
  • 40
  • 50
7

Solution 1 : You can Quit simulator and try again.

Solution 2 (Recommended) : Go to iOS Simulator -> Reset Content and Settings...

Step 1

This will pop-up an alert stating 'Are you sure you want to reset the iOS Simulator content and settings?'

Step 2

Select Reset if you wish to or else Don't Reset button.

Note that once you reset simulator content all app installed on simulator will be deleted and it will reset to initial settings.

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
7

I struggled with this for a couple of hours. Finally what solved it for me was:

sudo xcrun simctl erase all

xcrun simctl shutdown all

Yonatan Naor
  • 1,367
  • 18
  • 19
6

This could result from not setting the correct deployment info. (i.e. if your storyboard isn't set as the main interface)

Eric Hou
  • 341
  • 3
  • 9
  • I finally realized I was looking at `LaunchScreen.storyboard` when I should have been working with `Main.storyboard` . Once I figured that out, the screen appears with content. Thanks for the pointer here – Gene Bo Jun 29 '17 at 20:10
5

Another Solution is that if you are building UI programatically in Objective C project, then you might need to add some code to inflate the view, so you will need to add those 3 lines to make the window's interface interacts with the code (the outer 2 are actually interacting with the code and the other one will change the screen to white so you will know it works).

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

...

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];


return YES;
}
sivi
  • 10,654
  • 2
  • 52
  • 51
4

If you should loose your entry point in your Storyboard or simply wish to change the entry point you can specify this in Interface Builder. To set a new entry point you must first decide which ViewController will act as the new entry point and in the Attribute Inspector select the Initial Scene checkbox.

You can try: http://www.scott-sherwood.com/ios-5-specifying-the-entry-point-of-your-storyboard/

4

Please make sure you have done this,if you are getting black screen after copying the storyboard from another project enter image description here

Abhinav Jha
  • 295
  • 1
  • 17
3

What worked for me is remove the cache for Xcode and simulators. No need to uninstall them.

Goto ~/Library/Developer/Xcode remove, caches, ios device logs etc (all the temporary things, it will be pretty clear there which things are just temporary).

Then goto ~/Library/Developer/CoreSimulator and do the same with all the temporary files.

And note that, most probably, it is not an issue with your project but with the xcode and simulators.

Irfan wani
  • 4,084
  • 2
  • 19
  • 34
2

I solved this question with set window background color like this in iOS 13:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let _ = (scene as? UIWindowScene) else { return }
    if let windowScene = scene as? UIWindowScene {
        window = UIWindow(windowScene: windowScene)
        window?.backgroundColor = .white
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        
        // workaround for svprogresshud
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window = window
    }
}
2

I fixed this issue by cleaning the project by pressing
cmd + shift + k
and exited my simulator and built again.

candyline
  • 788
  • 8
  • 17
2

For me all it was needed was to shake the device (Device > Shake). Weird but worked for me. If this doesn't work try resetting (Device > Erase All Content and Settings) and then shake the device again.

Axel
  • 4,365
  • 11
  • 63
  • 122
0

I've managed to find the fix for this. It was found courtesy of this blog post:

http://vandadnp.wordpress.com/2012/03/18/xcode-4-3-1-cannot-attach-to-ios-simulator/

The solution is to press cmd+shift+, (command, shift and then comma ",").. that loads some options for release or debugging.

Change the debugger from LLDB to GDB. This fixes the issue.

Matt
  • 1,473
  • 2
  • 11
  • 13
  • 1
    The GDB debugger is deprecated and Xcode 4.6 is the last version to support it. https://developer.apple.com/library/mac/#releasenotes/DeveloperTools/RN-Xcode/ – Aaron Brager Feb 07 '13 at 20:53
0

To make sure it's a simulator issue, see if you can connect to the simulator with a brand new project without changing any code. Try the tab bar template.

If you think it's a simulator issue, press the iOS Simulator menu. Select "Reset Content and Settings...". Press "Reset."

I can't see your XIB and what @properties you have connected in Interface Builder, but it could also be that you're not loading your window, or that your window is not loading your view controller.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • Hi Aaron, thanks for the response. I tried just loading a blank project (tab bar and also empty application). It has the same issue. When using the LLDB debugger it fails *every* time. If I switch it to GDB, it then works fine. Seen your comment below on my answer about it being deprecated after 4.6. I just hope that something works when that time comes, because it seems to be the main issue. – Matt Feb 07 '13 at 23:20
0

I had the same issue with Xcode... black screen on launching apps, no debugging and clicking would lock up Xcode.

I finally found the problem... following the lead that the simulator could not connect to Xcode I took a look at my etc/hosts file and found that months ago to solve a different issue I had edited the host file to map localhost to my fixed IP instead of the default... my value:

10.0.1.17 localhost

This should work since that is my IP, but changing it back to the default IP fixed Xcode...

127.0.0.1 localhost

Hope this helps.

0

I was doing what doug suggests ("Reset Content and Settings") which works but takes a lot of time and it is really annoying... until I recently found completely accidental another solution that is much quicker and seems to also work so far! Just hit cmd+L on your simulator or go to the simulator menu "Hardware -> Lock", which locks the screen, when you unlock the screen the app works like nothing ever happened :)

Dimi Dim
  • 3
  • 1
0

What happened with me was the Type of class was not UIViewController for the script attached to my view controller. It was for a UITabController..... I had mistakenly quickly created the wrong type of class.... So make sure the class if the correct type.. Hope this helps someone. I was in a rush and made this mistake.

0

Just reset your simulator by clicking Simulator-> Reset Contents and Settings..

Pravin S.
  • 465
  • 7
  • 22
0

you could also go to Hardware -> reboot, then Hardware -> Home, and click on your App

coder666
  • 41
  • 7
0

Be sure that Initial View Controller is set

davut dev
  • 228
  • 1
  • 2
  • 11
0

I solved this only after removing simulators with prior iOS versions.

Eran Talmor
  • 1,918
  • 1
  • 12
  • 6
0

I had black simulator screens only for iOS 11 sims. After trying to reset, reboot, reinstall and creating a brand new useraccount on my machine I found this solution:

defaults write com.apple.CoreSimulator.IndigoFramebufferServices FramebufferRendererHint 3

found in this answer here: Xcode 9 iOS Simulator becoming black screen after installing Xcode 10 beta

Apoc
  • 797
  • 1
  • 10
  • 15
0

Please check for all the constraints for all the views and review complete storyboard. Usually this happens because of that.

Regards, Arora

Gaurav Arora
  • 121
  • 1
  • 3
0

In case you recently updated to Xcode 11 beta 3 and try to run an older SwiftUI project, you have to make some changes in the SceneDelegate where the views are loaded, otherwise the screens will remain black on devices running iOS 13 beta 3 which of course includes all simulators.

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    // Use a UIHostingController as window root view controller
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: ContentView())
        self.window = window
        window.makeKeyAndVisible()
    }
}

The behavior not strictly limited to the simulators, but since most people will run beta software exclusively on simulators it will only occur in this context. It baffled me for quite a while, so hope it helps.

Andy
  • 866
  • 9
  • 14
0

When i have carried my project on Xcode 11.1, i got that problem. That black screen problem may occur any presentation inter ViewControllers.

That answer helped me. Because modal presentation changed with iOS 13. If you don't get that problem before iOS 13, please try to add line below to your ViewController before its presentation;

viewController.modalPresentationStyle = .fullScreen

after your code may seem like below;

let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)
oguzhan
  • 2,073
  • 1
  • 26
  • 23
0

I was developing flutter using android studio and running the simulator, the simulator was dark and I reset the contents as per accepted answer. But that didn't fix my issue. My CPU was running somehow high enough, so I restarted , but not fixed the issue. I opened Xcode and run one of my native iOS apps, the simulator re-opened as usual. I closed the Xcode and opened Android Studio, then started developing flutter app again.

Ankur Lahiry
  • 2,253
  • 1
  • 15
  • 25
0

enter image description here

This was my reason for having this issue.

For some reason, the "Is Initial View Controller" (for my main View Controller) was unchecked which was causing the black screen on load up.

Hope this helps someone out there!

RVACode
  • 108
  • 4
0

I noticed I had accidentally deleted var window:UIWindow? line from AppDelegate. Introducing it again fixed the issue for me!

Mohit Singh
  • 1,452
  • 1
  • 18
  • 27
0

Faced this issue in Dec 2021 with iOS 13.7 simulator after Macbook Air went to sleep. The simulator screen was black with no signs of life. Resetting the simulator didn't help. Closing all windows and restarting the laptop didn't help. Ultimately it turned out that syspolicyd was hogging 350% of the CPU. Killing this process solved the problem.

kbrmys
  • 61
  • 6
0

For me, the simulator that was crashing was iPhone 13 with iOS 15.2. None of the solutions worked.

The CPU usage of the process 'syspolicyd' shot up whenever this issue occurred as well, but killing the process didn't help either.

Changing the device to a different one (File > Open Simulator > iOS 15.2 > iPhone 13 Pro Max) fixed the issue. After that, I started the previous device (iPhone 13) again, and it worked too.

tsb5555
  • 321
  • 3
  • 13
0

I was also getting the same problem but surprisingly what worked for me is

  • Open Xcode & Go to the Preferences > Components
  • Then, If you have not installed ios version then install from there (eg. iOS 15.2 that is required to run on iPhone 12 with iOS version 15.2)
  • After finish installation, Then click "Check & Install Now" button
  • Close the window & now run the simulator (for which you have installed version)
-1

Check right path for info.plist in Project - Build Sittings

Put info.plist into search field, and find line “info.plist File”

This in case of you move your info file into another folder.

V777
  • 85
  • 6
  • In Xcode 14 above they raised this issue as known for simulators Simulator Known Issues Repeated Build & Run targeting iOS 16.1 and later simulator runtimes may sometimes result in a hung launch. (101990080) Workaround: Reboot the simulator device and reattempt the launch. – Adarsh KC Mar 21 '23 at 07:10
-1

I've Xcode 13.2.1

What worked for me is on the Simulator Menu. Go to Device and Erase All Content and Settings...

leo
  • 113
  • 3
  • 11