I have a problem in my SwiftUI project, I try to use mobile authentication with firebase, when I put my number and click the button , it is throw an error as a
If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotification: method.
I am still do not understand what I missed?
@State var no = ""
@State var show = false
@State var msg = ""
@State var alert = false
@State var ID = ""
var body : some View{
VStack{
TextField("No",text:self.$no)
NavigationLink(destination: CodeView(show: $show, ID: $ID), isActive: $show)
{
Button {
PhoneAuthProvider.provider().verifyPhoneNumber(self.no, uiDelegate: nil)
{ (ID, err) in
if err != nil{
self.msg = (err?.localizedDescription)!
self.alert.toggle()
return
}
self.ID = ID!
self.show.toggle()
}
} label: {
Text("OK")
.padding()
}
}
} .alert(isPresented: $alert) {
Alert(title: Text("Error"), message: Text(self.msg), dismissButton:
.default(Text("Ok")))
}
}
CodeView:
@State var scode = ""
@State var show = false
@State var msg = ""
@State var alert = false
@State var ID = ""
VStack {
TextField("SMS Code", text: self.$scode)
NavigationLink(destination: HomeView(), isActive:
$show) {
Button {
let credential = PhoneAuthProvider.provider().credential(withVerificationID:
self.ID, verificationCode: self.scode)
Auth.auth().signIn(with: credential) { (res, err) in
if err != nil{
self.msg = (err?.localizedDescription)!
self.alert.toggle()
return
}
UserDefaults.standard.set(true, forKey: "status")
NotificationCenter.default.post(name:
NSNotification.Name("statusChange"), object: nil)
}
} label: {
Text("Next")
.padding()
}
} .alert(isPresented: $alert) {
Alert(title: Text("Error"), message: Text(self.msg),
dismissButton: .default(Text("Ok")))
}
MyApp:
import SwiftUI
import Firebase
@main
struct App: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
ZStack{
ContentView()
}
}
}
}