macos flutter_如何在MacOS上将iOS Flutter应用程序与Firebase集成

macos flutter

Firebase is a mobile app development platform developed by Firebase, Inc. in 2011, and then Acquired by Google in 2014. It provides various features such as Cloud Storage, Authentication and an ML kit, which are essential to developing modern mobile applications.

Firebase是由Firebase,Inc.于2011年开发,然后于2014年被Google收购的移动应用程序开发平台。它提供了各种功能,例如云存储,身份验证和ML套件,这些功能对于开发现代移动应用程序至关重要。

Additionally, it provides services such as Performance Monitoring, Crashlytics and Google Analytics to help you improve the quality of your applications.

此外,它还提供诸如性能监控,Crashlytics和Google Analytics(分析)之类的服务,以帮助您提高应用程序的质量。

In this tutorial I am going to show you how to connect your Flutter iOS application to the Firebase Platform on a Mac Computer, so you can utilize the powerful services provided by the firebase API in your future endeavors…

在本教程中,我将向您展示如何将Flutter iOS应用程序连接到Mac计算机上的Firebase平台,以便在将来的工作中利用firebase API提供的强大服务…

1.准备一个Gmail帐户和一个Flutter项目 (1. Readying a Gmail Account and a Flutter Project)

In order to utilize services from Firebase and Google Cloud Platform, you will need a Google Account. If you do not have one, simply following the page instructions here to register for one.

为了利用Firebase和Google Cloud Platform的服务,您将需要一个Google帐户。 如果您没有,请按照此处的页面说明注册一个。

This tutorial is going to show you how to connect your existing Flutter application to the Firebase platform. If you are interested in how to create your first Flutter application, I have a tutorial on How to create your first iOS Flutter app on MacOS. By the end of that tutorial, you should have a hello_world application ready in the simulator and understand how to alter the application by modifying the main.dart file.

本教程将向您展示如何将现有的Flutter应用程序连接到Firebase平台。 如果您对如何创建第一个Flutter应用程序感兴趣,请阅读有关如何在MacOS上创建第一个iOS Flutter应用程序的教程。 在该教程结束之前,您应该在模拟器中准备好hello_world应用程序,并了解如何通过修改main.dart文件来更改应用程序。

2.创建Firebase项目 (2. Creating a Firebase Project)

In order to integrate your Flutter application with the Firebase Platform, first you have to create a Firebase Project. And here are the steps.

为了将Flutter应用程序与Firebase平台集成,首先必须创建一个Firebase项目。 这是步骤。

1. Go to the Firebase Console.

1.转到Firebase控制台

2. Click on the big Add project button.

2.单击大的添加项目按钮。

3. Enter your Project name.

3.输入您的项目名称

  • I used hello-world for this example. Firebase automatically appends a unique ID to your project name — for example, the project I created ended up with the name hello-world-f2206.

    在此示例中,我使用了hello-world 。 Firebase会自动在您的项目名称后附加一个唯一ID,例如,我创建的项目最终以名称hello-world-f2206结束

4. You can pick a Cloud Firestore Location.

4.您可以选择一个Cloud Firestore位置。

  • I left it as nam5 (us-central) because I live in Los Angeles, but the Cloud Functions are not available on us-west2, and the traffic in between will create additional charges. You can find more about service availabilities and server locations here.

    我将其保留为nam5(us-central),因为我住在洛杉矶,但是us-west2上不提供Cloud Functions,并且两者之间的流量会产生额外的费用。 您可以在此处找到有关服务可用性和服务器位置的更多信息。

5. Accept the Terms and Conditions.

5.接受条款和条件

5. Once you are done, scroll to the bottom and click Create Project.

5.完成后,滚动到底部,然后单击创建项目

  • See 3.1 Switching to Administrator Account in the appendix at the end of this article if you encountered an error message asking for an administrator account.

    如果遇到错误消息询问管理员帐户 ,请参阅本文末尾的3.1切换到管理员帐户。

Firebase will take some time to ready your application. Once done, click on the Continue button to open up the Firebase Project Overview Page.

Firebase将花费一些时间来准备您的应用程序。 完成后,单击继续按钮以打开Firebase项目概述页面

4.配置iOS应用程序 (4. Configure an iOS Application)

1. In your Firebase Project Overview Page, launch the setup wizard for iOS.

1.在Firebase项目概述页面中 ,启动iOS的设置向导。

2. Inside the setup wizard, put in the iOS bundle ID. The Register app button should then light up, click on it.

2.在设置向导中,放入iOS捆绑包ID。 然后, 注册应用程序按钮应点亮,单击它。

  • A guide on how to find the iOS bundle ID can be found the below in section 4.1 Finding iOS Project root folder & Acquiring Bundle ID of the appendix.

    有关如何查找iOS捆绑包ID的指南,请参见下面的4.1查找iOS项目根文件夹和获取附录的捆绑包ID

3. Download the GoogleService-Info.plist configuration file and put it into the iOS Project root folder, then click Next.

3.下载GoogleService-Info.plist中的配置文件,并把它插入iOS项目根文件夹,然后单击下一步

  • A guide on how to find the iOS bundle ID can be found below in section 4.1 Finding iOS Project root folder & Acquiring Bundle ID of the appendix.

    有关如何查找iOS捆绑包ID的指南,请参见下面的4.1查找iOS项目根文件夹和获取附录的捆绑包ID

4. Follow the instructions to add the Firebase SDK, then click Next.

4.按照说明添加Firebase SDK ,然后单击“ 下一步”

  • A detailed guide on how to install CocoaPods and Firebase SDK can be found below in section 4.2 Installing CocoaPods and Firebase SDK.

    有关如何安装CocoaPodsFirebase SDK的详细指南,请参见下面的4.2安装CocoaPods和Firebase SDK

5. Modify the code inside the main AppDelegate as instructed by the setup wizard then click Next. For this example, I used Objective-C, and therefore replaced the contents inside AppDelegate.m with the following code.

5.按照设置向导的指示,在主AppDelegate中修改代码,然后单击“ 下一步” 。 对于此示例,我使用了Objective-C ,因此用以下代码替换了AppDelegate.m中的内容。

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"

@import UIKit;
@import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIRApp configure];
return YES;
}

@end

6. Get back to the root folder and run your app, after a while you should see the setup wizard showing that your app is added to Firebase. Click Continue to the Console to finish the setup.

6.回到根文件夹并运行您的应用程序,过一会儿,您将看到安装向导,显示您的应用程序已添加到Firebase。 单击继续到控制台以完成设置。

Congratulations! You have successful added Firebase to your Flutter application. Despite the fact that having both Firebase and Flutter from Google is supper cool, it is actually a good Software Engineering practice to always have a plan B, as well as plan C, D,E, F, and G. In the future I will write another guide on an example application utilizing Firebase, and more on Flutter.

恭喜你! 您已成功将Firebase添加到Flutter应用程序中。 尽管同时拥有Google的Firebase和Flutter都超酷,但始终拥有计划B以及计划C,D,E,F和G实际上是一种好的软件工程实践。在将来,我会在使用Firebase的示例应用程序上写另一本指南,在Flutter上写更多的指南。

Have fun coding!!!

玩得开心!

附录: (Appendices:)

3.1切换到管理员帐户 (3.1 Switching to Administrator Account)

If you ran into the following message, it means that you need to contact the organization of your Gmail account to grant you access to Google Developers Console.

如果您遇到以下消息,则意味着您需要联系Gmail帐户的组织以授予您对Google Developers Console的访问权限。

4.1查找iOS项目根文件夹并获取捆绑包ID (4.1 Finding iOS Project root folder & Acquiring Bundle ID)

1. Launch Xcode from the Launchpad.

1.从启动板启动Xcode

2. Select “Open another project…” at the bottom of the prompt screen.

2.在提示屏幕底部选择“打开另一个项目…”

3. Navigate to your Flutter project folder, open the “ios” folder and select “Runner.xcodeproj”. This should automatically open up the project in Xcode.

3.导航到Flutter项目文件夹,打开“ ios”文件夹,然后选择“ Runner.xcodeproj” 。 这应该会自动在Xcode中打开项目。

4. Select the Runner project on the left, you should now see the Bundle Identifier under Identity.

4.选择左侧的Runner项目,您现在应该在Identity下方看到Bundle Identifier

4.2安装CocoaPods和Firebase SDK (4.2 Installing CocoaPods and Firebase SDK)

In case the instructions inside the setup wizard did not work out, you will have to remove the existing Podfile in order to reinstall them correctly.

如果安装向导中的说明无法解决,则必须删除现有的Podfile才能正确地重新安装它们。

1. CocoaPods is built with Ruby and is installable with the default Ruby available on MacOS. Use the following commands to install it.

1. CocoaPods是使用Ruby构建的,并且可以使用MacOS上可用的默认Ruby安装。 使用以下命令进行安装。

sudo gem install cocoapods

2. Initialize the Podfile with the following command.

2.使用以下命令初始化Podfile

pod init

3. Then, add the following code to the initialized Podfile.

3.然后,将以下代码添加到初始化的Podfile中

pod 'Firebase/Core'

4. Once done, save the changes made to the Podfile, and install the Firebase SDK with the following command.

4.完成后,保存对Podfile所做的更改,并使用以下命令安装Firebase SDK

pod install

5. After the installation, you will likely have to configure the .xcconfig files. First you will have to copy the files from the Pods/Target Support Files/Pods-Runner folder to Flutter folder.

5.安装后,您可能必须配置 xcconfig文件。 首先,您必须将文件从Pods / Target支持文件/ Pods-Runner文件夹复制到Flutter文件夹。

6. Then you will have to include them into the Debug.xcconfig and Release.xcconfig files inside the Flutter folder.

6.然后,您必须将它们包含在Flutter文件夹内的Debug.xcconfigRelease.xcconfig文件中。

In Debug.xcconfig:

Debug.xcconfig中

#include "Pods-Runner.debug.xcconfig"

In Release.xcconfig:

Release.xcconfig中

#include "Pods-Runner.profile.xcconfig"
#include "Pods-Runner.release.xcconfig"

翻译自: https://www.freecodecamp.org/news/how-to-integrate-your-ios-flutter-app-with-firebase-on-macos-6ad08e2714f0/

macos flutter

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值