Flutter iOS物理设备使用FirebaseAuth登录报错 模拟器正常如何解决
Flutter+FirebaseAuth iOS物理设备侧载登录故障说明
我使用Flutter与FirebaseAuth开发了一款简单应用,支持用户输入邮箱和密码完成登录,该应用在iOS模拟器中运行完全符合预期,但我将应用侧载到iOS物理设备时出现多个报错,登录流程失败,应用无法继续后续运行。以下是相关代码、报错信息,以及已尝试但未生效的排查解决步骤:
相关代码
import 'dart:async'; import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'screens/other/LoadingScreen.dart'; import 'screens/other/ErrorScreen.dart'; import 'screens/other/SignupScreen.dart'; import 'screens/other/HomeScreen.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { // This widget is the root of your application. @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<CovidHound> { bool _initialized = false; bool _error = false; String _email = ""; String _password = ""; void initializeFlutterFire() async { try { await Firebase.initializeApp(); print("Init firebase"); setState(() { _initialized = true; }); } catch (e) { print("Error init firebase:${e}"); setState(() { _error = true; }); } } Future<void> onTapSignIn() async { try { await FirebaseAuth.instance .signInWithEmailAndPassword(email: _email, password: _password); } on FirebaseAuthException catch (e) { if (e.code == 'user-not-found') { print('No user found for that email.'); } else if (e.code == 'wrong-password') { print('Wrong password provided for that user.'); } } catch (e) { print("Error signing in: $e"); } if (FirebaseAuth.instance.currentUser != null) { Navigator.push( context, MaterialPageRoute( builder: (context) => HomeScreen(), fullscreenDialog: true, ), ); } } @override void initState() { super.initState(); initializeFlutterFire(); } @override Widget build(BuildContext context) { if(_error) { return ErrorScreen(); } if (!_initialized) { return LoadingScreen(); } return MaterialApp( home: Scaffold( body: Center( child: Column( children: [ TextField( decoration: InputDecoration(hintText: "Email"), onChanged: (value) { _email = value; }, ), TextField( decoration: InputDecoration(hintText: "Password"), onChanged: (value) { _password = value; }, ), TextButton( onPressed: () { onTapSignIn(); }, child: Text("Sign In"), ), ], ), ), ), ); } }
报错信息



已尝试的排查步骤
- 按照官方文档正确配置Firebase
- 执行
flutter clean清理Xcode工作空间与构建产物 - 将iOS系统与Xcode升级至最新版本
- 升级Flutter版本
- 参照官方文档说明,在info.plist中添加Privacy - Local Network Usage Description权限
内容的提问来源于stack exchange,提问作者Heshara Aluthge
相关产品推荐
相关产品推荐

