Sunday, June 23, 2024
HomeiOS Developmentios - Unable to ship SMS with code, SwiftUI, FireBase Authentication, ERROR...

ios – Unable to ship SMS with code, SwiftUI, FireBase Authentication, ERROR 17999 and ERROR 17010


I’m growing an app on IOS 17+, my firebase-ios-sdk 10.18.0, Xcode 15.4. I have to implement login and registration within the app utilizing telephone quantity. However resulting from a number of sorts of errors I’m not capable of ship sms.

The primary error is

Error throughout telephone quantity verification: An inside error has occurred, print and examine the error particulars for extra data. Firebase Error Code: FIRAuthErrorCode(rawValue: 17999)

it seems most frequently and is accompanied by the error

https://www.googleapis.com/identitytoolkit/v3/relyingparty/sendVerificationCode, Response code: 503

in addition to much less ceaselessly seems the error

Error throughout telephone quantity verification: We’ve got blocked all requests from this machine resulting from uncommon exercise. Strive once more later. Firebase Error Code: FIRAuthErrorCode(rawValue: 17010)

and is accompanied by the error

https://www.googleapis.com/identitytoolkit/v3/relyingparty/sendVerificationCode, Response code: 400

I’ve tried many options and here’s what I can say

  1. I’ve after all enabled registration with telephone quantity in FireBase and Google Cloud Platform

  2. Registration and Authentication works appropriately should you add a check telephone quantity

  3. The error isn’t associated to reCaptcha, because it passes efficiently and I’ve rechecked the URL schemes

  4. In Google Cloud Platform I’ve enabled “Cloud Identification” and “Identification Toolkit API”

  5. The error additionally has nothing to do with APNs Authentication Key, as a result of I can ship notifications through Cloud Messaging with none issues.

  6. I’ve additionally linked my bank card.

Right here is my code for AppDelegate and capabilities associated to sending a message

    func startAuth(phoneNumber: String, completion: @escaping (Bool) -> Void) {
        print("Beginning telephone quantity verification for: (phoneNumber)")
        
        // Установить isAppVerificationDisabledForTesting в true для тестирования
       // Auth.auth().settings?.isAppVerificationDisabledForTesting = true
        
        PhoneAuthProvider.supplier().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { verificationID, error in
            if let error = error {
                print("Error throughout telephone quantity verification: (error.localizedDescription)")
                if let errorCode = AuthErrorCode.Code(rawValue: (error as NSError).code) {
                    print("Firebase Error Code: (errorCode)")
                }
                completion(false)
                return
            }
            UserDefaults.commonplace.set(verificationID, forKey: "authVerificationID")
            completion(true)
        }
    }

    func verifyCode(smsCode: String, completion: @escaping (Bool) -> Void) {
        guard let verificationID = UserDefaults.commonplace.string(forKey: "authVerificationID") else {
            completion(false)
            return
        }
        let credential = PhoneAuthProvider.supplier().credential(withVerificationID: verificationID, verificationCode: smsCode)
        Auth.auth().signIn(with: credential) { authResult, error in
            if let error = error {
                print("Error verifying code: (error)")
                completion(false)
                return
            }
            completion(true)
        }
    }
    
    func resendCode(completion: @escaping (Bool) -> Void) {
            guard let phoneNumber = tempUserData?["phoneNumber"] as? String else {
                completion(false)
                return
            }

            startAuth(phoneNumber: phoneNumber) { success in
                completion(success)
            }
        }

    func registerUser(userData: [String: Any], completion: @escaping (Bool) -> Void) {
        let db = Firestore.firestore()
        guard let uid = Auth.auth().currentUser?.uid else {
            completion(false)
            return
        }
        db.assortment("customers").doc(uid).setData(userData) { error in
            if let error = error {
                print("Error registering person: (error)")
                completion(false)
                return
            }
            completion(true)
        }
    }

and

class AppDelegate: NSObject, UIApplicationDelegate {
    func software(_ software: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        
//        let providerFactory = AppCheckDebugProviderFactory()
//        AppCheck.setAppCheckProviderFactory(providerFactory)
                let providerFactory = YourAppCheckProviderFactory()
                AppCheck.setAppCheckProviderFactory(providerFactory)
        
        FirebaseApp.configure()
        print("App Examine supplier manufacturing facility set")

        // Запрос разрешения на отправку уведомлений
        UNUserNotificationCenter.present().requestAuthorization(choices: [.alert, .badge, .sound]) { granted, error in
            print("Permission granted: (granted)")
        }
        software.registerForRemoteNotifications()
        print("Distant notifications registered")

        return true
    }

    func software(_ software: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Information) {
        // Обработка регистрации удаленных уведомлений
        Auth.auth().setAPNSToken(deviceToken, sort: .unknown)
        print("Distant notifications token registered")
    }

    func software(_ software: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        // Обработка ошибки регистрации удаленных уведомлений
        print("Did not register for distant notifications: (error.localizedDescription)")
    }

    func software(_ software: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Обработка полученных уведомлений
        if Auth.auth().canHandleNotification(userInfo) {
            completionHandler(.noData)
            return
        }
        // This notification isn't dealt with by Firebase Authentication.
        // Deal with the notification your self, as applicable.
    }
}

class YourAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
  func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
    if #obtainable(iOS 14.0, *) {
      return AppAttestProvider(app: app)
    } else {
      return DeviceCheckProvider(app: app)
    }
  }



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments