在xcode11上创建的工程在iOS13以下的版本上运行会黑屏,对比xcode11和xcode10创建的工程,可以发现:
在xcode10创建的工程目录包括:
AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m
在xcode11创建的工程目录包括
AppDelegate.h
AppDelegate.m
SceneDelegate.h
SceneDelegate.m
ViewController.h
ViewController.m
在xcode11的工程中新增了SceneDelegate.h/SceneDelegate.m,而在AppDelegate.h中去掉了window的属性和一些生命周期方法。
SceneDelegate主要用于支持iPadOS的多窗口,旧版本中的生命周期和window移到了UIScene中去管理了,用AppDelegate管理单个或多个UIScene,一个UIScene管理单个或多个UIWindow。AppDelegate (UIApplicationDelegate)控制生命周期的行为移交给了SceneDelegate (UIWindowSceneDelegate)。
但是在iOS13以下版本根本没有UIScene这一层,这就会导致运行时出现黑屏,解决方法就是在AppDelegate.h中添加一个window
的属性。
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@end
如果不想使用Scene,可以在info.plist中删除UIApplicationSceneManifest (Application Scene Manifest),然后删除掉所有跟Scene有关的代码,就走的以前的AppDelegate的那些生命周期方法了。