Building Spotify App in Swift 5 & UIKit - Part 27 - Sign Out (Xcode 12, 2021, Swift 5) - Build App
alert
public func signOut(completionHandler: (Bool) -> ()) {
UserDefaults.standard.setValue(nil, forKey: "access_token")
UserDefaults.standard.setValue(nil, forKey: "refresh_token")
UserDefaults.standard.setValue(nil, forKey: "expirationDate")
completionHandler(true)
}
private func signOutTapped() {
let alert = UIAlertController(title: "Sign Out",
message: "Are you sure?",
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Sign Out", style: .destructive, handler: { _ in
AuthManager.shared.signOut { [weak self] signOut in
guard let self = self else { return }
if signOut {
DispatchQueue.main.async {
let navVC = UINavigationController(rootViewController: WelcomeViewController())
navVC.navigationBar.prefersLargeTitles = true
navVC.viewControllers.first?.navigationItem.largeTitleDisplayMode = .always
navVC.modalPresentationStyle = .fullScreen
self.present(navVC, animated: true) {
self.navigationController?.popToRootViewController(animated: false)
}
}
}
}
}))
present(alert, animated: true)
}
alert
를 통해 확인하기popToRootViewController
로 빠져나간 뒤 WelcomeViewController
를 띄우기