felon
felon

Reputation: 183

AppDelegate l WalkthroughView

i can add WalkthroughView on UIViewController pages but how i can add WalkthroughView on appDelegate?

 override open func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let defaults = UserDefaults.standard
    let hasViewedWalkthrough = defaults.bool(forKey: "hasViewedWalkthrough")

    if !hasViewedWalkthrough {
       //
        print("succes")
        //
       if let pageVC = storyboard?.instantiateViewController(withIdentifier: "WalkthroughViewController") as? WalkthroughViewController {
           present(pageVC, animated: true, completion: nil)
        }
   }
}

Upvotes: -2

Views: 70

Answers (2)

ViR
ViR

Reputation: 286

Perhaps you mean one of the options?

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        let rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "WalkthroughViewController")
        window = UIWindow(frame: UIScreen.main.bounds)

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

        return true
    }
}

Or:

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
            let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "WalkthroughViewController")
             window?.rootViewController?.present(viewController, animated: true, completion: nil)
        }

        return true
    }
}

Upvotes: 1

Sumit Singh
Sumit Singh

Reputation: 1

You can use the app delegate for this

func application(_ application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool

Upvotes: -1

Related Questions