14

I am building a screen with phone number login. I checked over and over again and the project is newly created, however, I am getting this log:

7.2.0 - [Firebase/Auth][I-AUT000015] The UIApplicationDelegate must handle remote notification for phone number authentication to work. If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

I did read in the documentation about swizzling and I don't know why it seems to be disabled, I did not disabled it. I have added GoogleServices-Info.plist into the app, I added in firebase panel the app apn auth key.

My entry point in the app looks like this:

@main struct partidulverdeApp: App { init() { FirebaseApp.configure() } var body: some Scene { WindowGroup { MainView() .onOpenURL { url in Auth.auth().canHandle(url.absoluteURL) } } } } 

My URL Types property has an entry with the RESERVED_CLIENT_ID

I am very desperate about this problem. Any idea is highly appreciated.

Edit1:

I did read the documentation and tried to handle notification with swizzling disabled, but I get the same error:

class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { if Auth.auth().canHandleNotification(notification) { completionHandler(.noData) return } } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { print("Your code here") return true } } @main struct partidulverdeApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate init() { FirebaseApp.configure() } var body: some Scene { WindowGroup { MainView() .onOpenURL { url in Auth.auth().canHandle(url.absoluteURL) } } } } 
3
  • See here. To add an AppDelegate to your app, see here Commented Dec 22, 2020 at 13:35
  • @koen I edited my question. Long story short, I already tried that several times without any result. I have the same error. Do you have any idea why it's not working? Commented Dec 22, 2020 at 13:52
  • Ohh, now I see that I get: You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist. I will look how to solve it. Commented Dec 22, 2020 at 13:56

2 Answers 2

25

Here's how to implement Phone Number Auth using the new SwiftUI 2 life cycle:

  1. Create a Firebase project and set up PhoneNumber Auth

  2. Add your iOS app to the Firebase project, download and add GoogleService-Info.plist to your project

  3. In Xcode, select the application target and enable the following capabilities:

    • Push notifications
    • Background modes > Remote notifications
  4. Create and register an APNS authentication key on the Apple developer portal

  5. Upload the key to Firebase (under Project Settings > Cloud messaging in the Firebase Console)

  6. Add the Firebase project's reversed client ID to your app's URL schemes

  7. In your Info.plist, set FirebaseAppDelegateProxyEnabled to NO

  8. Implement the AppDelegate as follows:

class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { FirebaseApp.configure() print("SwiftUI_2_Lifecycle_PhoneNumber_AuthApp application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.") return true } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { print("\(#function)") Auth.auth().setAPNSToken(deviceToken, type: .sandbox) } func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("\(#function)") if Auth.auth().canHandleNotification(notification) { completionHandler(.noData) return } } func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool { print("\(#function)") if Auth.auth().canHandle(url) { return true } return false } } @main struct SwiftUI_2_Lifecycle_PhoneNumber_AuthApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate var body: some Scene { WindowGroup { ContentView() .onOpenURL { url in print("Received URL: \(url)") Auth.auth().canHandle(url) // <- just for information purposes } } } } 

For further reading, I suggest these two articles I wrote:

Sign up to request clarification or add additional context in comments.

5 Comments

is it necessary to disable swizzling? I've gotten phone auth & FCMs to work with swizzling but I've noticed some weird side effects.
Can you elaborate how you got it working with swizzling (feel free to share a link to a GitHub repo / Gist so I can take a look), @bze12?
gist.github.com/benedelstein/8965d8b1eb9df9a63869cf493323dc39 I just set up the delegate similar to your answer, but never disabled swizzling. I'm able to receive cloud notifications and do phone auth without captcha, but the only weird thing is that my didRegisterForRemoteNotificationsWithDeviceToken is never called.
When I move FirebaseApp.configure() from app init to AppDelegate, Firebase Crashylitics is not working anymore (at least in my app).
@emreoktem did you find any fix for the issue ?
-1

This requires Apple Developer Program to use Push Notifications. But Even if you use ReCaptcha method redirecting into Safari.. It still gives you swizzling disabled error.

 import SwiftUI import SwiftData import FirebaseCore import FirebaseAuth @main struct WhatsAppApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate init() { FirebaseApp.configure() if let firebaseApp = FirebaseApp.app() { print("Firebase configured successfully: \(firebaseApp)") } else { print("Firebase configuration failed!") } Auth.auth().settings?.isAppVerificationDisabledForTesting = true print("Firebase Auth settings updated (Testing mode enabled)") } var body: some Scene { WindowGroup { ContentView() .onOpenURL { url in print("Received URL: \(url)") Auth.auth().canHandle(url) } } } } 
import SwiftUI import UIKit import FirebaseAuth import Firebase class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { print("\(#function)") Auth.auth().setAPNSToken(deviceToken, type: .sandbox) } func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("\(#function)") if Auth.auth().canHandleNotification(notification) { completionHandler(.noData) return } } func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool { print("\(#function)") if Auth.auth().canHandle(url) { return true } return false } } 

ERROR :

Firebase configured successfully: <FIRApp: 0x600000c02460> Firebase Auth settings updated (Testing mode enabled) 11.9.0 - [GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol. 
Firebase Phone Auth Error: FIRAuthErrorDomain 17054 - If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need tobe forwarded to FirebaseAuth's canHandleNotification method. User Info: ["FIRAuthErrorUserInfoNameKey": "ERROR_NOTIFICATION_NOT_FORWARDED", "NSLocalizedDescription": "If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FirebaseAuth\'s canHandleNotification method."] 

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.