firebase ios_适用于Android和iOS的Firebase实时数据库登录教程

firebase ios

Mobile apps need a backend. They store settings & data, high scores, check licenses and generate statistics. All these use cases have one thing in common: they use a central database.

移动应用程序需要后端。 他们存储设置和数据,高分,检查许可证并生成统计信息。 所有这些用例都有一个共同点:它们使用中央数据库。

Coding a full-blown backend takes a lot of time. Think about end-to-end security, communication interfaces and database structure. When you then get to details like concurrent access, it gets tricky.

编码一个完整的后端需要很多时间。 考虑端到端的安全性,通信接口和数据库结构。 然后,当您获得诸如并发访问之类的详细信息时,就会很棘手。

Luckily, Google Firebase takes care of all these issues for you. It’s a ready-to-use cloud-hosted database with full authentication support. In contrast to a traditional SQL database, Google Firebase stores JSON data sets (-> NoSQL). This gives you more flexibility in your data structure.

幸运的是, Google Firebase会为您解决所有这些问题。 这是一个具有完整身份验证支持的即用型云托管数据库。 与传统SQL数据库相比,Google Firebase存储JSON数据集(-> NoSQL )。 这为您的数据结构提供了更大的灵活性。

On top of that, you can subscribe to real-time data changes. You’ll get notified about updates made to the data, for example by other users. The service does offer a simple REST API. But the most efficient communication is a publish & subscribe model via websockets.

最重要的是,您可以订阅实时数据更改。 您将收到有关数据更新的通知,例如其他用户。 该服务确实提供了简单的REST API 。 但是最有效的通信是通过websockets的发布和订阅模型。

That sounds complicated? Google offers a separate SDK for each platform. With Felgo & Qt, you don’t need to worry about platform differences. Felgo includes a cross-platform Google Firebase Realtime Database plugin. The same QML / JavaScript-based API works for both Android & iOS.

听起来复杂吗? Google为每个平台提供了单独的SDK。 使用Felgo&Qt,您无需担心平台差异。 Felgo包含一个跨平台的Google Firebase实时数据库插件 。 相同的基于QML / JavaScript的API适用于Android和iOS。

If you need help with that, consult or outsource your app development with Felgo.

如果您需要帮助,请向Felgo咨询或外包您的应用程序开发

入门 (Getting Started)

In this Firebase tutorial, you’ll complete the full journey from start to end. You start with a project template of Qt Creator. Next, you’ll set up the Firebase service in the cloud. Another important task is user authentication. Most impressive: live database updates from & to your cross-platform app.

在此Firebase教程中,您将完成从头到尾的整个旅程。 您将从Qt Creator的项目模板开始。 接下来,您将在云中设置Firebase服务。 另一个重要任务是用户身份验证。 最令人印象深刻的是:从&跨平台应用实时更新数据库。

The scenario is a simple shopping list. It’s a generic app that includes everything most apps need. Authentication, plus adding, updating and deleting items. Once you understand the concepts, it’s easy to adapt them to your own scenario.

该方案是一个简单的购物清单。 这是一个通用应用程序,其中包含大多数应用程序需要的所有内容。 身份验证,以及添加,更新和删除项目。 一旦理解了这些概念,就很容易将它们适应您自己的方案。

If you’re impatient, skip right to the final project source code on GitHub.

如果您不耐烦,请直接跳至GitHub上的最终项目源代码。

在YouTube上观看本教程 (Watch this Tutorial on YouTube)

You can also watch the video version of this tutorial on YouTube. It is very much in-depth and covers every single step of the process.

您也可以在YouTube上观看本教程的视频版本。 它非常深入,涵盖了过程的每个步骤。

您的Cloud Backend的主从UI (Master-Detail UI for your Cloud Backend)

Curious to dive right into the cloud database? Well, you will need your “app package name” for Android and the “iOS bundle ID” when setting up Firebase.

是否想直接进入云数据库? 好了,设置Firebase时,您将需要Android的“应用程序包名称”和“ iOS软件包ID”。

Thus, start with the app and make your life easier. Open Qt Creator and create a new project. Use the “Felgo Apps” > “Master-Detail Application”. This gives you great boilerplate code for any list-type app.

因此,从该应用程序开始,使您的生活更轻松。 打开Qt Creator并创建一个新项目。 使用“ Felgo应用程序”>“主从应用程序”。 这为您提供了任何列表类型应用程序的出色样板代码。

Image for post

In step 2, choose the kits for the target platforms: Android and/or iOS.

在步骤2中,选择目标平台的工具包:Android和/或iOS。

Take special note of the “Felgo Project Properties” page (step 3). Here, you define the app identifier, which you will also need for the Firebase setup. In this case, choose com.vplay.ShoppingList.

特别注意“ Felgo项目属性”页面(步骤3)。 在这里,您可以定义应用程序标识符,Firebase设置也需要该标识符。 在这种情况下,请选择com.vplay.ShoppingList

Image for post

Google offers different Firebase samples for individual platforms & tools. With Felgo, you run the same code across Android & iOS. Activate the “Google Firebase” plugin. It includes ready-made cross-platform code to interact with the Google cloud!

Google针对各个平台和工具提供了不同的Firebase示例。 使用Felgo,您可以在Android和iOS上运行相同的代码。 激活“ Google Firebase”插件。 它包括现成的跨平台代码,可与Google云进行交互!

Image for post

在Android和iOS上进行实时测试 (Live Testing on Android & iOS)

If you target both Android and iOS, you’ll want to test your app on both platforms. Felgo Live immediately deploys and executes any code changes on any connected phone. You can even connect and test on iOS phones while developing on Windows. You save an incredible amount of time: no more re-building, deploying and testing.

如果您同时定位Android和iOS,则需要在两个平台上测试您的应用。 Felgo Live立即在任何连接的电话上部署并执行任何代码更改。 在Windows上进行开发时,您甚至可以在iOS手机上进行连接和测试。 您节省了不可思议的时间:无需重新构建,部署和测试。

Image for post

To get started, download the Felgo Live app from the app store: Android / iOS. Next, make sure your development computer and the phone are on the same local network. Start the Felgo Live app on your phone and connect it to your Live Server. If your Live Server is not running yet, click on “Live Run” in Qt Creator, to start developing with live code reloading!

首先,请从以下应用商店中下载Felgo Live应用: Android / iOS 。 接下来,确保您的开发计算机和电话在同一本地网络上。 在手机上启动Felgo Live应用程序,然后将其连接到Live Server。 如果您的Live Server尚未运行,请在Qt Creator中单击“ Live Run”,开始使用实时代码重新加载进行开发!

Felgo插件许可证 (Felgo Plugin License)

Your app currently shows a watermark that you’re running a trial of the Firebase plugin. That’s fine for your first testing steps! To get rid of the trial watermark and the license reminders, you need the Felgo Indie license. If you do not have an Indie license, you can continue using the Firebase plugin in trial mode, without generating a license key.

您的应用当前显示一个水印,表明您正在试用Firebase插件。 这对您的第一个测试步骤很好! 要摆脱试用水印和许可证提醒,您需要Felgo Indie许可证。 如果您没有独立许可证,则可以在试用模式下继续使用Firebase插件,而无需生成许可证密钥。

Authorization works through a license key for your app. Go to https://felgo.com/upgradeLicense. Select the “Google Firebase” plugin. Next, click the green “Generate License Key” button at the bottom of the page.

授权通过您的应用程序的许可证密钥进行。 前往https://felgo.com/upgradeLicense 。 选择“ Google Firebase”插件。 接下来,单击页面底部的绿色“ Generate License Key”按钮。

Image for post

Next, enter your app identifier (e.g., “com.vplay.ShoppingList”). The suggested version “1” is correct — it’s the default in every new project.

接下来,输入您的应用标识符(例如,“ com.vplay.ShoppingList”)。 建议的版本“ 1”是正确的-这是每个新项目中的默认版本。

Image for post

Copy the new license key to your code, add it to the licenseKey property in your Main.qml file. The watermark disappears. This video shows the original Master-Detail sample app. When inserting the license key to the code, the app instantly reloads — without the watermark. Afterwards, you see a brief demo of the initial app functionality.

将新的许可证密钥复制到您的代码中,然后将其添加到Main.qml文件中的licenseKey属性中。 水印消失。 该视频显示了原始的Master-Detail示例应用程序。 将许可证密钥插入代码时,该应用程序会立即重新加载-不带水印。 之后,您将看到有关初始应用程序功能的简短演示。

Image for post

创建Firebase项目 (Create the Firebase Project)

Congratulations, your master-detail app is running on the phone! Now, it’s time to create the Google Firebase Realtime database. This serves as complete lightweight backend for the shopping list example app.

恭喜,您的主从应用程序正在手机上运行! 现在,该创建Google Firebase Realtime数据库了。 这可作为购物清单示例应用程序的完整轻量级后端。

To create a Firebase account, go to the Firebase homepage. Login with your Google Account to see the empty console. The project you create runs great with the free account. You don’t need to worry about payments.

要创建Firebase帐户,请转到Firebase主页 。 使用您的Google帐户登录以查看空白控制台。 您创建的项目使用免费帐户运行良好。 您无需担心付款。

First, click on “Add project”.

首先,单击“添加项目”。

Image for post

Give your project a name to recognize it in your console: “ShoppingList”. The “Project ID” is auto-generated with a number, as it needs to be globally unique. You can customize the ID if you like. Note that your users will never see this ID, though — so don’t spend too much time here.

为您的项目命名,以便在控制台中识别它:“ ShoppingList”。 “项目ID”会自动生成一个数字,因为它必须是全局唯一的。 您可以根据需要自定义ID。 请注意,尽管如此,您的用户将永远不会看到此ID,因此请不要在这里花费太多时间。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是使用Firebase_Messaging接收推送通知的完整Flutter iOS代码: ```dart import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance; @override void initState() { super.initState(); _firebaseMessaging.requestPermission(); _firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print("onMessage: $message"); showDialog( context: context, builder: (context) { return AlertDialog( content: ListTile( title: Text(message['notification']['title']), subtitle: Text(message['notification']['body']), ), actions: <Widget>[ FlatButton( child: Text('Ok'), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); }, onResume: (Map<String, dynamic> message) async { print("onResume: $message"); }, onLaunch: (Map<String, dynamic> message) async { print("onLaunch: $message"); }, ); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Firebase Messaging', home: Scaffold( appBar: AppBar( title: Text('Flutter Firebase Messaging'), ), body: Center( child: Text('Welcome to Flutter Firebase Messaging'), ), ), ); } } ``` 在这个例子中,我们首先使用Firebase.initializeApp()初始化Firebase应用程序,然后创建FirebaseMessaging实例并调用requestPermission()请求权限。接下来,我们使用configure()方法配置FirebaseMessaging以处理不同的消息事件。当应用程序处于前台时,onMessage()方法被调用,我们在这里创建一个AlertDialog来显示推送通知的标题和正文。当应用程序处于后台或未运行时,onResume()和onLaunch()方法被调用,我们可以在这里处理推送通知。 希望这个例子能够帮助你使用Firebase_Messaging接收推送通知。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值