首页 > 解决方案 > iOS13 App黑屏,self.window不工作

问题描述

在我的测试 iPhone 设备升级到版本 13.3 后,我self.window的不再工作了。我试过如下:

  1. 选择目标 -> 常规 -> 部署信息,清理“主界面”。

  2. 删除了 info.plist 中的“故事板名称 -> main”,删除了 info.plist 中的“主故事板文件基本名称”,删除了 info.plist 中与 main.storyboard 相关的任何内容。

  3. 在 didFinishLaunchingWithOptions 中添加代码:

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = KWhiteColor;
    [self.window makeKeyAndVisible];

但是启动App还是黑屏。有没有人可以告诉我为什么以及如何进行self.window工作?

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

    //初始化window
//    [self initWindow];
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = KWhiteColor;
    [self.window makeKeyAndVisible];

    //初始化服务
    [self initService];

    //初始化用户系统
//    [self initUserManager];
    CSKLoginViewController *vc = [CSKLoginViewController new];
    //        vc.showBack = NO;
//    RootNavigationController *loginNavi = [[RootNavigationController alloc] initWithRootViewController:vc];
    vc.view.backgroundColor = UIColor.redColor;
    self.window.rootViewController = vc;

    return YES;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>xxx</string>
    <key>CFBundleDevelopmentRegion</key>
    <string>zh_CN</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>NSCameraUsageDescription</key>
    <string></string>
    <key>NSContactsUsageDescription</key>
    <string>访问您的通讯录新增客户。&lt;/string>
    <key>NSMicrophoneUsageDescription</key>
    <string></string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string></string>
    <key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <false/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>SceneDelegate</string>
                </dict>
            </array>
        </dict>
    </dict>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

标签: iosobjective-c

解决方案


问题是你的代码放错了地方。窗口不再属于应用委托;它属于场景委托。


推荐阅读