ios 从Xcode启动iOS模拟器,黑屏,接着Xcode挂了,无法停止任务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14668445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Launch iOS simulator from Xcode and getting a black screen, followed by Xcode hanging and unable to stop tasks
提问by Matt
I'm having trouble running my basic iPhone application (while going through the Stanford iTunes CS193p lectures) in the iOS simulator.
我在 iOS 模拟器中运行我的基本 iPhone 应用程序时遇到了问题(同时进行了斯坦福 iTunes CS193p 讲座)。
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.
我已经搜索了一段时间(Google 和 SO),但到目前为止找不到解决方案。有许多类似的错误,但解决方案似乎并没有解决这个问题。
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.
在 Xcode 中,我单击“运行”。它成功编译和构建,启动 iOS 模拟器,但它永远不会加载应用程序。只有顶部的状态栏。带黑屏。
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.
更令人困惑的是,我(UIWebView)
在这些讲座之前写了一个 web 包装器,这很好用。但是代码几乎没有任何区别。我从头开始创建的所有新应用程序都因相同的黑屏问题而失败。
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.
如果我点击模拟器上的主页按钮并启动应用程序,它将显示。但是Xcode似乎不知道发生了什么。
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.
就好像 Xcode 失去了与 iOS 模拟器对话的能力,并假设它正在运行(即使我退出了 iOS 模拟器)。我尝试退出 Xcode,它要求我停止任务。然后它就挂了。所以我必须强制重启才能退出 Xcode。
I'm using: OSX 10.8.2 Xcode 4.5.2 iOS Simulator 6.0
我正在使用:OSX 10.8.2 Xcode 4.5.2 iOS 模拟器 6.0
CalculatorAppDelegate.h
CalculatorAppDelegate.h
#import <UIKit/UIKit.h>
@interface CalculatorAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
CalculatorAppDelegate.m
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
CalculatorViewController.h
#import <UIKit/UIKit.h>
@interface CalculatorViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *display;
@end
CalculatorViewController.m
CalculatorViewController.m
#import "CalculatorViewController.h"
@implementation CalculatorViewController
@synthesize display = _display;
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = [sender currentTitle];
NSLog(@"digit pressed = %@", digit);
}
@end
回答by doug
Surprisingly, what worked for me was going to iOS Simulator menu, and pressing "Reset Content and Settings". (in iOS 13, its under Hardware)
令人惊讶的是,对我有用的是转到 iOS 模拟器菜单,然后按“重置内容和设置”。(在 iOS 13 中,它在硬件下)
回答by Chris
Before resetting the emulator first go to your projects "project navigator" screen and under the general-> depoyment infoscreen check that the main interfaceproperty is properly setup!
在重置模拟器之前,首先转到您的项目“项目导航器”屏幕,然后在常规->部署信息屏幕下检查主界面属性是否已正确设置!
回答by bauerMusic
If you're using SwiftUI
如果您使用的是 SwiftUI
If you're updating from a previous version of Xcode 11, there are some changes to the SceneDelegate
willConnectTo session: options connectionOptions
initialization:
如果您是从先前版本的 Xcode 11 进行更新,则SceneDelegate
willConnectTo session: options connectionOptions
初始化会有一些更改:
The main window
is now initialized using UIWindow(windowScene: windowScene)
, where it use to be UIWindow(frame: UIScreen.main.bounds)
现在主要window
使用 初始化UIWindow(windowScene: windowScene)
,它曾经是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()
}
回答by asdf
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
我是 iOS 应用程序开发的新手。我从一开始就在练习开发 iOS 应用程序,在运行一个非常基本的 Hello World 应用程序时,我也遇到了同样的问题,即在 iOS 模拟器中构建和运行应用程序后只出现黑屏。不知何故,在努力寻找问题的解决方案时,我不小心点击了 iOS 模拟器中的 Window-->Scale-->50% ,它确实解决了我的问题。然后我可以看到带有我的应用程序的主页并单击应用程序图标我能够成功运行我的应用程序。应用程序版本:Xcode 5.1 iOS 模拟器:7.1 OSX:10.9.3
回答by Eric Hou
This could result from not setting the correct deployment info. (i.e. if your storyboard isn't set as the main interface)
这可能是由于未设置正确的部署信息造成的。(即,如果您的故事板未设置为主界面)
回答by sivi
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).
另一个解决方案是,如果您在 Objective C 项目中以编程方式构建 UI,那么您可能需要添加一些代码来扩充视图,因此您需要添加这 3 行代码以使窗口的界面与代码交互(外部 2实际上正在与代码交互,而另一个会将屏幕更改为白色,以便您知道它有效)。
- (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;
}
回答by Jayprakash Dubey
Solution 1 :You can Quit simulator
and try again.
解决方案 1:您可以Quit simulator
再试一次。
Solution 2(Recommended) : Go to iOS Simulator
-> Reset Content and Settings...
解决方案 2(推荐):转到iOS Simulator
->Reset Content and Settings...
This will pop-up an alert stating 'Are you sure you want to reset the iOS Simulator content and settings?'
这将弹出一个警告说明 'Are you sure you want to reset the iOS Simulator content and settings?'
Select Reset
if you wish to or else Don't Reset
button.
选择Reset
您是否愿意或其他Don't Reset
按钮。
Note that once you reset simulator content all app installed on simulator will be deleted and it will reset to initial settings.
请注意,一旦您重置模拟器内容,模拟器上安装的所有应用程序都将被删除,并将重置为初始设置。
回答by user2101881
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.
如果您应该在 Storyboard 中丢失您的入口点,或者只是希望更改入口点,您可以在 Interface Builder 中指定它。要设置新的入口点,您必须首先决定哪个 ViewController 将充当新的入口点,然后在 Attribute Inspector 中选择 Initial Scene 复选框。
You can try: http://www.scott-sherwood.com/ios-5-specifying-the-entry-point-of-your-storyboard/
你可以试试:http: //www.scott-sherwood.com/ios-5-specifying-the-entry-point-of-your-storyboard/
回答by Lolo
Restarting your computer should be all you need to do.
您只需要重新启动计算机即可。