I am trying to login account using phone number authentication using firebase.
Initially, i deployed the app with my device and it works fine. But when i tried to d
Follow steps
1) Import Firebase and FirebaseAuth
import Firebase
import FirebaseAuth
2) In didFinishLaunchingWithOptions Configure firebase.
FirebaseApp.configure()
3) Write these two func in AppDelegate.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.prod)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let firebaseAuth = Auth.auth()
if (firebaseAuth.canHandleNotification(userInfo)){
print(userInfo)
return
}
}
4) In your ViewController class, repeat step first and write code for send OTP on Mobile Number, which you want.
@IBAction func sendCodeAction(_ sender: Any) {
let ugrMgr = UserManager.userManager
let phoneNumber = Auth.auth().currentUser?.phoneNumber
print(phoneNumber!)
print(ugrMgr.mobile!)
PhoneAuthProvider.provider().verifyPhoneNumber("+91" + ugrMgr.mobile!, uiDelegate: nil) { (verificationID, error) in
if let error = error {
print(error.localizedDescription)
mainInstance.ShowAlertWithError(error.localizedDescription as NSString, msg: error.localizedDescription as NSString)
return
}
self.verificationID = verificationID
}
}