使用xcode11新建工程,target选择iOS13以下版本,app启动黑屏。
处理方案:
swift :
在appdelegate 类添加window属性
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
oc:
在appdelegate类中为window成员变量添加_window属性
@implementation AppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if (@available(ios 13, *)) {
} else {
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc]init]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
}
return YES;
}
iOS13系统window加载代码在ScreenDelegate文件中
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
// 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).
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc]init]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
}