LoginSignup
1
0

More than 1 year has passed since last update.

FlutterfireでiOSの電話認証(phone authentication)にハマった

Last updated at Posted at 2022-04-01

問題

公式ドキュメントに従ってiOSの電話認証を実装したら、以下のエラーが吐き出された。

If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotification: method

flutter version: 2.10.3

解決策

参考:https://github.com/firebase/flutterfire/issues/1102#issuecomment-581202025

リンク内のコードから若干修正した(元のコードだとライブラリがないと怒られた)

ios/Runner/AppDelegate.swift を以下の内容で上書きする。リビルドすると解決。

import UIKit
import Flutter
import Firebase
import FirebaseAuth
import UserNotifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
        FirebaseApp.configure()
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

    }
    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let firebaseAuth = Auth.auth()
        if (firebaseAuth.canHandleNotification(userInfo)){
            print(userInfo)
            return
        }
    }
}


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0