From 8c9f6d5d32b9cbb4e60bcb1abc55879b948b38e9 Mon Sep 17 00:00:00 2001 From: talksik Date: Fri, 17 Dec 2021 23:32:51 -0800 Subject: [PATCH] removing some stuff regarding apn's and such and slowly improving smoothness of the phone auth as it's still long time --- .../PhoneVerificationView.swift | 55 ++++++++++++------- nirvana-ios/nirvana_iosApp.swift | 30 ++++++---- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/nirvana-ios/Views/PhoneVerification/PhoneVerificationView.swift b/nirvana-ios/Views/PhoneVerification/PhoneVerificationView.swift index c8bde45..25ab97e 100644 --- a/nirvana-ios/Views/PhoneVerification/PhoneVerificationView.swift +++ b/nirvana-ios/Views/PhoneVerification/PhoneVerificationView.swift @@ -19,7 +19,8 @@ struct PhoneVerificationView: View { // Alert settings @State var showToast = false - @State var toastText = "🇺🇸 Only U.S. supported, more countries coming soon!" + @State var toastText = "" + @State var toastSubMessage = "" // TODO: format the input so that it shows the parentheses and stuff (949)923-0445 var body: some View { @@ -62,25 +63,31 @@ struct PhoneVerificationView: View { .padding(.vertical, 20) Button { - print("send sms") - let concatPhoneNumber = "+"+self.ccode+self.phoneNumber - // do auth stuff from firebase + // do auth stuff from firebase PhoneAuthProvider.provider() .verifyPhoneNumber(concatPhoneNumber, uiDelegate: nil) { verificationID, error in // problem verifying number showing alert...maybe fake number or something from user if error != nil { - self.toastText = (error?.localizedDescription)! + self.toastText = "⚠️ Please try again." + self.toastSubMessage = "There was an issue validating your phone number" self.showToast.toggle() + + print((error?.localizedDescription)!) + return } - // Sign in using the verificationID and the code sent to the user - // ... + + print("sending sms") + + // TODO: Sign in using the verificationID and the code sent to the user + // if there is no user with the phone number, then create one UserDefaults.standard.set(verificationID, forKey: "authVerificationID") // then async send to next page + // TODO: coming back after function end and then having 1 second before hitting this...need to use async and combine and all of that to make sure that the main thread is not affected and it's all smooth self.navigationStack.push(PhoneVerificationCodeView()) // verify code page } } label: { @@ -97,7 +104,7 @@ struct PhoneVerificationView: View { Text("You might receive an SMS message for verification and standard rates apply.") .font(.footnote) - .foregroundColor(Color.black.opacity(0.7)) + .foregroundColor(Color.gray) } } } @@ -115,11 +122,12 @@ struct PhoneVerificationView: View { .padding() } } - .alert(isPresented: self.$showToast) { - Alert( - title: Text(self.toastText), - dismissButton: .default(Text("Got it!")) - ) + .alert(self.toastText, isPresented: self.$showToast) { + + Button("OK", role: ButtonRole.cancel) { } + + } message: { + Text(self.toastSubMessage) } } } @@ -138,7 +146,8 @@ struct PhoneVerificationCodeView: View { // Alert settings @State var showToast = false - @State var toastText = "There was an error in verifying your account" + @State var toastText = "" + @State var toastSubMessage = "" var body: some View { ZStack(alignment: .topLeading) { @@ -181,11 +190,14 @@ struct PhoneVerificationCodeView: View { verificationCode: self.verificationCode ) - // firebase will now verify the put together credential + // firebase will now verify the credential Auth.auth().signIn(with: credential) { (res, err) in if err != nil { - self.toastText = (err?.localizedDescription)! + self.toastText = "⚠️ Error with Verification" + self.toastSubMessage = "Code is invalid. Please try again or re-enter your phone number in the previous page." self.showToast.toggle() + + print((err?.localizedDescription)!) return } @@ -229,11 +241,12 @@ struct PhoneVerificationCodeView: View { .padding() } } - .alert(isPresented: self.$showToast) { - Alert( - title: Text(self.toastText), - dismissButton: .default(Text("Got it!")) - ) + .alert(self.toastText, isPresented: self.$showToast) { + + Button("OK", role: ButtonRole.cancel) { } + + } message: { + Text(self.toastSubMessage) } } } diff --git a/nirvana-ios/nirvana_iosApp.swift b/nirvana-ios/nirvana_iosApp.swift index 482bcf8..244d2c4 100644 --- a/nirvana-ios/nirvana_iosApp.swift +++ b/nirvana-ios/nirvana_iosApp.swift @@ -28,21 +28,29 @@ struct nirvana_iosApp: App { class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { - FirebaseApp.configure() - return true + print("Colors application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.") + + print("initialized Firebase") + FirebaseApp.configure() + return true } - func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { - print("\(#function)") - Auth.auth().setAPNSToken(deviceToken, type: .sandbox) - } + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + print("\(#function)") + //MARK: add this when I have APN setup through app + // gets the APN token so that firebase can send notifications to app +// Auth.auth().setAPNSToken(deviceToken, type: .sandbox) + } func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { + print("did receive remote notification") print("\(#function)") - if Auth.auth().canHandleNotification(notification) { - completionHandler(.noData) - return - } + //MARK: add this when I have APN setup through app +// if Auth.auth().canHandleNotification(notification) { +// completionHandler(.noData) +// return +// } + } // For iOS 9+ @@ -50,7 +58,7 @@ class AppDelegate: NSObject, UIApplicationDelegate { // MARK: turned off google sign in link in for phone below // return GIDSignIn.sharedInstance.handle(url) - // if the user can be handled by google auth, then it will do so + // if the url has to do with phone auth, then it will do so if Auth.auth().canHandle(url) { return true }