У меня есть UITabBarController
как rootviewcontroller с 4 вкладками и вход в систему с помощью кнопки Apple, которая регистрирует вас и представляет UITabBarController
. Однако, когда я вхожу только через Apple ... данные загружаются только на первую вкладку ... и все остальные вкладки остаются пустыми, как обычная раскадровка ... другой вход с помощью Google и Facebook загружает все данные вкладок, кроме входа Apple ?? Я не могу понять почему .. Я представляю каждую раскадровку с modalPresentingStyle= .fullScreen
.
import UIKit
import AuthenticationServices
class LoginVC: UIViewController, ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
@IBOutlet weak var appleBtn: Button!
var userEmail: String?
var savedUserID: String?
override func viewDidLoad() {
super.viewDidLoad()
appleBtn.addTarget(self, action: #selector(handleAppleIdRequest), for: .touchUpInside)
performExistingAccountSetupFlows()
// Do any additional setup after loading the view.
}
@objc func handleAppleIdRequest() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.performRequests()
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
// Create an account in your system.
// For the purpose of this demo app, store the these details in the keychain.
KeychainItem.currentUserIdentifier = appleIDCredential.user
KeychainItem.currentUserFirstName = appleIDCredential.fullName?.givenName
KeychainItem.currentUserLastName = appleIDCredential.fullName?.familyName
KeychainItem.currentUserEmail = appleIDCredential.email
print("User Id - \(appleIDCredential.user)")
print("User Name - \(appleIDCredential.fullName?.description ?? "N/A")")
print("User Email - \(appleIDCredential.email ?? "N/A")")
print("Real User Status - \(appleIDCredential.realUserStatus.rawValue)")
if let identityTokenData = appleIDCredential.identityToken,
let identityTokenString = String(data: identityTokenData, encoding: .utf8) {
print("Identity Token \(identityTokenString)")
}
//Show Home View Controller
guard let tabBar = self.storyboard?.instantiateViewController(withIdentifier: "tabBar") as? UITabBarController else { return }
self.present(tabBar, animated: true, completion: nil)
} else if let passwordCredential = authorization.credential as? ASPasswordCredential {
// Sign in using an existing iCloud Keychain credential.
let username = passwordCredential.user
let password = passwordCredential.password
// For the purpose of this demo app, show the password credential as an alert.
DispatchQueue.main.async {
let message = "The app has received your selected credential from the keychain. \n\n Username: \(username)\n Password: \(password)"
let alertController = UIAlertController(title: "Keychain Credential Received",
message: message,
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
}
func performExistingAccountSetupFlows() {
// Prepare requests for both Apple ID and password providers.
let requests = [ASAuthorizationAppleIDProvider().createRequest(),
ASAuthorizationPasswordProvider().createRequest()]
// Create an authorization controller with the given requests.
let authorizationController = ASAuthorizationController(authorizationRequests: requests)
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
@IBAction func otherSignUP(_ sender: Any) {
guard let otherLogin = self.storyboard?.instantiateViewController(identifier: "otherLogin") as? OtherLoginVC else {return}
otherLogin.modalPresentationStyle = .fullScreen
self.present(otherLogin, animated: true, completion: nil)
}
}