Home > Blockchain >  can't create an app programmatically for older iOS versions on xCode 12
can't create an app programmatically for older iOS versions on xCode 12

Time:10-07

I can't create an app programmatically for older iOS versions on Xcode 12. There's my code in AppDelegate.swift

    @main
    class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Set the window bounds
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()

        window?.rootViewController = UINavigationController(rootViewController: ViewController())
        
        return true
    }
  }

There's my ViewController:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .white
    }


}

I looked for a solution on the internet but could not find. I deleted the Main.storyboard and SceneDelegate.swift files. I delete key/value main in info.plist file. And I remove Main.storyboard into Main Interface

CodePudding user response:

don't remove the sceneDelegate file its a bad practice, appDelegate will deprecate soon... if you need setup for devices use iOS 12 or older versions.. try use this..

in sceneDelegate...

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

        guard let scene = (scene as? UIWindowScene) else { return }

        let floatVersion = (UIDevice.current.systemVersion as NSString).floatValue

        if floatVersion >= 13 {
            window = UIWindow(windowScene: scene)
            window?.makeKeyAndVisible()
            
            let controller = YourController()
            let navigation = UINavigationController(rootViewController: controller)

            window?.rootViewController = navigation
        }
    }

and use this in appDelegate.. only for Devices use iOS 12 or older inside on appDelegate file


var window: UIWindow?

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        let floatVersion = (UIDevice.current.systemVersion as NSString).floatValue
        if floatVersion <= 12.5 {
            window = UIWindow(frame: UIScreen.main.bounds)
            window?.makeKeyAndVisible()
            
// if you use a navigation... 
            let controller = YourController()
            let navigation = UINavigationController(rootViewController: controller)
            window?.rootViewController = navigation
        } 
      
        return true
    }
 

try use break points in scene delegate and appDelegate inside the validations, using simulator with iOS 12 versions, and iOS 13 versions or newest... and will work, but don't delete sceneDelegate, checkout the wwdc swift news.

I had the same problem 2 years ago, and I use this option currently and still work for me, I hope this will help.

CodePudding user response:

Thank you for your answer. I solve my problem. And problem is actually solved with delete (key,value) Application-Scene-Manifest option in info.plist file. See this link for image scene manifest

  • Related