AppDelegate l WalkthroughView
Я могу добавить WalkthroughView
на UIViewController
страницы, но как я могу добавить WalkthroughView
на 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)
}
}
}
2 ответа
Возможно, вы имеете в виду один из вариантов?
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
}
}
Или же:
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
}
}
Вы можете использовать приложение делегата для этого
func application(_ application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool