gpt4 book ai didi

ios - 如果 App delegate 想要使用主 Storyboard文件,它必须实现 window 属性

转载 作者:行者123 更新时间:2023-12-01 15:57:10 24 4
gpt4 key购买 nike

我已经尝试了我在 stackoverflow 中找到的所有解决方案,但没有一个有效。

这是我当前的 AppDelegate.swift 文件,我认为我正在以某种方式实现窗口属性:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow()
window?.makeKeyAndVisible()
let mainVC = UIViewController()
window?.rootViewController = mainVC

return true
}

// MARK: UISceneSession Lifecycle
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
window = UIWindow()
window?.makeKeyAndVisible()
let mainVC = UIViewController()
window?.rootViewController = mainVC
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
window = UIWindow()
window?.makeKeyAndVisible()
let mainVC = UIViewController()
window?.rootViewController = mainVC
}

可能会发生什么,所以警告仍然出现并且我的应用程序一直显示黑屏?

最佳答案

我一步一步地指导你。

  1. 第 1 步从项目中删除 SceneDelegate 文件。
  2. var window: UIWindow? 添加到 AppDelegate。
  3. 从 AppDelegate 中删除以下函数。

    //标记:UISceneSession 生命周期

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
  4. Info.plist 文件中删除 Application Scene Manifest 键。


额外

AppDelegate 文件中添加以下委托(delegate)方法,在 didFinishLaunchingWithOptions

下方
    func applicationWillResignActive(_ application: UIApplication) {
// 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.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// 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.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// 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.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

关于ios - 如果 App delegate 想要使用主 Storyboard文件,它必须实现 window 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60393478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com