首次启动应用程序 Xcode 11 iOS 13 后如何使入职场景消失

Posted

技术标签:

【中文标题】首次启动应用程序 Xcode 11 iOS 13 后如何使入职场景消失【英文标题】:How do I make onboarding scene disappear after first launching app Xcode 11 iOS 13 【发布时间】:2020-02-22 15:26:17 【问题描述】:

我对此很陌生,但遇到了问题。我的目标是制作一个欢迎您使用该应用程序的入职屏幕。我希望它在第一次启动应用程序后消失。我关注了这个tutorial。我没有将代码放在AppDelegate 中,而是将代码放在SceneDelegate 下:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) 
...

这是我到目前为止的代码:

导入 UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate 

    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) 

        let launchedBefore = UserDefaults.standard.bool(forKey: "hasLaunched")
            self.window? = UIWindow(frame: UIScreen.main.bounds)
            let launchStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let mainStoryboard = UIStoryboard(name: "actual", bundle: nil)

            var vc: UIViewController

            if launchedBefore
            

                vc = mainStoryboard.instantiateInitialViewController()!

            
            else
            
                vc = launchStoryboard.instantiateViewController(identifier: "firststoryboard")
            
            UserDefaults.standard.set(true, forKey: "hasLaunched")

        self.window?.rootViewController = vc
        self.window?.makeKeyAndVisible()

        // 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).
        guard let _ = (scene as? UIWindowScene) else  return 



    


    func sceneDidDisconnect(_ scene: UIScene) 
        // Called as the scene is being released by the system.
        // This occurs shortly after the scene enters the background, or when its session is discarded.
        // Release any resources associated with this scene that can be re-created the next time the scene connects.
        // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
    

    func sceneDidBecomeActive(_ scene: UIScene) 
        // Called when the scene has moved from an inactive state to an active state.
        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
    

    func sceneWillResignActive(_ scene: UIScene) 
        // Called when the scene will move from an active state to an inactive state.
        // This may occur due to temporary interruptions (ex. an incoming phone call).
    

    func sceneWillEnterForeground(_ scene: UIScene) 
        // Called as the scene transitions from the background to the foreground.
        // Use this method to undo the changes made on entering the background.
    

    func sceneDidEnterBackground(_ scene: UIScene) 
        // Called as the scene transitions from the foreground to the background.
        // Use this method to save data, release shared resources, and store enough scene-specific state information
        // to restore the scene back to its current state.
    


现在我没有收到任何错误,但是当我启动应用程序时屏幕是黑色的。有谁知道我做错了什么?

【问题讨论】:

您将代码放入场景委托中真是很棒。但是您没有向我们显示代码,因此我们不知道您可能做错了什么。如果您需要帮助,请显示您的代码。总是。这是适用于 ios 12 和 iOS 13 的可下载示例:github.com/mattneub/RegistrationExample/blob/master/… 嗨对不起!忘了把重要的部分放进去。我现在编辑了我的消息 删除此行:self.window? = UIWindow(frame: UIScreen.main.bounds)。这不是在场景委托中创建窗口的正确方法。 【参考方案1】:

我不知道你是否找到了答案,但我只是问了一个基本相同的问题并得到了回答:How to make Onboarding work with Scene Delegate in iOS13?

【讨论】:

以上是关于首次启动应用程序 Xcode 11 iOS 13 后如何使入职场景消失的主要内容,如果未能解决你的问题,请参考以下文章

iOS 13.3 (Xcode 11.3.1) 下的模拟器无法正常运行

如何在 Xcode 11 中启动没有故事板 >= iOS 13 的新项目?

自 xCode 13 和 iOS 15 以来,Appium(和桌面)无法启动 wda 会话

应用程序卡在带有 Xcode 11 测试版的 iOS 13 测试版模拟器上,但在带有 Xcode 10 的 iOS 13 测试版模拟器上运行良好

Xcode UI 测试:如何测试应用程序的首次启动

iOS 13:Flurry Unity SDK 启动时应用程序崩溃