import'package:flutter/material.dart';import'package:firebase_core/firebase_core.dart';// Import the firebase_app_check pluginimport'package:firebase_app_check/firebase_app_check.dart';Future<void>main()async{WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp();awaitFirebaseAppCheck.instance.activate(// Set appleProvider to `AppleProvider.debug`appleProvider:AppleProvider.debug,);runApp(App());}
在 Xcode 项目(v11.0 或更高版本)中启用调试日志记录:
打开 Product(产品)> Scheme(方案)> Edit scheme(修改方案)。
从左侧菜单中选择 Run(运行),然后选择 Arguments(参数)标签页。
在 Arguments Passed on Launch(启动参数)部分,添加 -FIRDebugEnabled。
import'package:flutter/material.dart';import'package:firebase_core/firebase_core.dart';// Import the firebase_app_check pluginimport'package:firebase_app_check/firebase_app_check.dart';Future<void>main()async{WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp();awaitFirebaseAppCheck.instance.activate(webRecaptchaSiteKey:'recaptcha-v3-site-key',// Set androidProvider to `AndroidProvider.debug`androidProvider:AndroidProvider.debug,);runApp(App());}
当 Firebase 尝试向后端发送请求时,您的应用会将一个本地调试令牌发送到调试输出中。例如:
D DebugAppCheckProvider: Enter this debug secret into the allow list in
the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678
[null,null,["最后更新时间 (UTC):2025-08-12。"],[],[],null,["After you have registered your app for App Check, your app normally won't run\nin an emulator or from a continuous integration (CI) environment, since those\nenvironments don't qualify as valid devices. If you want to run your app in such\nan environment during development and testing, you can create a debug build of\nyour app that uses the App Check debug provider instead of a real attestation\nprovider.\n| **Warning:** The debug provider allows access to your Firebase resources from unverified devices. Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties.\n\nApple platforms\n\nTo use the debug provider while running your app in a simulator interactively\n(during development, for example), do the following:\n\n1. Activate App Check with the debug provider right after you have initialized\n your Firebase app:\n\n import 'package:flutter/material.dart';\n import 'package:firebase_core/firebase_core.dart';\n\n // Import the firebase_app_check plugin\n import 'package:firebase_app_check/firebase_app_check.dart';\n\n Future\u003cvoid\u003e main() async {\n WidgetsFlutterBinding.ensureInitialized();\n await Firebase.initializeApp();\n await FirebaseAppCheck.instance.activate(\n // Set appleProvider to `AppleProvider.debug`\n appleProvider: AppleProvider.debug,\n );\n runApp(App());\n }\n\n2. Enable debug logging in your Xcode project (v11.0 or newer):\n\n 1. Open **Product \\\u003e Scheme \\\u003e Edit scheme**.\n 2. Select **Run** from the left menu, then select the **Arguments** tab.\n 3. In the **Arguments Passed on Launch** section, add `-FIRDebugEnabled`.\n3. Open `ios/Runner.xcworkspace` with Xcode and run your app in the Simulator.\n Your app will print a local debug token to the debug output when Firebase\n tries to send a request to the backend. For example:\n\n ```\n Firebase App Check Debug Token:\n 123a4567-b89c-12d3-e456-789012345678\n ```\n4. In the [**App Check**](//console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, register the debug token you logged in the previous\n step.\n\nAfter you register the token, Firebase backend services will accept it as valid.\n\nBecause this token allows access to your Firebase resources without a\nvalid device, it is crucial that you keep it private. Don't commit it to a\npublic repository, and if a registered token is ever compromised, revoke it\nimmediately in the Firebase console.\n\nAndroid\n\nTo use the debug provider while running your Flutter app in an Android environment,\nimplement the following code in your Flutter application: \n\n import 'package:flutter/material.dart';\n import 'package:firebase_core/firebase_core.dart';\n\n // Import the firebase_app_check plugin\n import 'package:firebase_app_check/firebase_app_check.dart';\n\n Future\u003cvoid\u003e main() async {\n WidgetsFlutterBinding.ensureInitialized();\n await Firebase.initializeApp();\n await FirebaseAppCheck.instance.activate(\n webRecaptchaSiteKey: 'recaptcha-v3-site-key',\n // Set androidProvider to `AndroidProvider.debug`\n androidProvider: AndroidProvider.debug,\n );\n runApp(App());\n }\n\nYour app will print a local debug token to the debug output when Firebase tries\nto send a request to the backend. For example: \n\n```\nD DebugAppCheckProvider: Enter this debug secret into the allow list in\nthe Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678\n```\n\n1. In the [**App Check**](//console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, register the debug token you logged in the previous\n step.\n\nAfter you register the token, Firebase backend services will accept it as valid.\n\nWeb\n\nTo use the debug provider while running your app from `localhost` (during\ndevelopment, for example), do the following:\n| **Warning:** *Do not* try to enable `localhost` debugging by adding `localhost` to reCAPTCHA's allowed domains. Doing so would allow anyone to run your app from their local machines!\n\n1. In the file `web/index.html`, enable debug mode by setting\n `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to `true`:\n\n \u003cbody\u003e\n \u003cscript\u003e\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;\n \u003c/script\u003e\n\n ...\n\n \u003c/body\u003e\n\n2. Run your web app locally and open the browser's developer tool. In the\n debug console, you'll see a debug token:\n\n ```\n AppCheck debug token: \"123a4567-b89c-12d3-e456-789012345678\". You will\n need to safelist it in the Firebase console for it to work.\n ```\n\n This token is stored locally in your browser and will be used whenever you\n use your app in the same browser on the same machine. If you want to use the\n token in another browser or on another machine, set\n `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to the token string instead of `true`.\n3. In the [**App Check**](//console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, register the debug token you logged in the previous\n step.\n\nAfter you register the token, Firebase backend services will accept it as valid.\n\nBecause this token allows access to your Firebase resources without a\nvalid device, it is crucial that you keep it private. Don't commit it to a\npublic repository, and if a registered token is ever compromised, revoke it\nimmediately in the Firebase console."]]