תחילת העבודה עם מסד נתונים בזמן אמת ב-Firebase עבור C++
קל לארגן דפים בעזרת אוספים אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
ב-Firebase Realtime Database, הנתונים מאוחסנים ומסונכרנים באמצעות מסד נתונים בענן מסוג NoSQL. הנתונים מסונכרנים עם כל הלקוחות בזמן אמת, ונשארים זמינים גם כשהאפליקציה עוברת למצב אופליין.
שימו לב שהוספת Firebase לפרויקט C++ כוללת משימות במסוף Firebase ובפרויקט C++ הפתוח (לדוגמה, הורדה של קובצי תצורה של Firebase מהמסוף והעברה שלהם לפרויקט C++).
יצירת מסד נתונים
עוברים לקטע Realtime Database במסוף Firebase. תתבקשו לבחור פרויקט קיים ב-Firebase. פועלים לפי תהליך העבודה ליצירת מסד נתונים.
בוחרים מצב התחלתי ל-Firebase Security Rules:
מצב בדיקה
החשבון הזה מתאים להתחלת העבודה עם ספריות לקוח לנייד ולאינטרנט, אבל כל אחד יכול לקרוא ולשכתב את הנתונים שלכם. אחרי הבדיקה, חשוב לעיין בקטע הסבר על כללי Firebase Realtime Database.
כדי להתחיל להשתמש ב-SDK לאתרים, ל-Apple או ל-Android, בוחרים באפשרות testmode.
מצב נעילה
דחיית כל פעולות הקריאה והכתיבה מלקוחות ניידים ומלקוחות אינטרנט. שרתי האפליקציות המאומתים שלכם עדיין יכולים לגשת למסד הנתונים.
בוחרים מיקום למסד הנתונים.
בהתאם למיקום של מסד הנתונים, כתובת ה-URL של מסד הנתונים החדש תהיה באחד מהפורמטים הבאים:
DATABASE_NAME.firebaseio.com (למסדי נתונים ב-us-central1)
DATABASE_NAME.REGION.firebasedatabase.app (למסדי נתונים בכל המיקומים האחרים)
לוחצים על סיום.
כשמפעילים את Realtime Database, מערכת Cloud API Manager מפעילה גם את ה-API.
יצירה ואתחול של firebase::App
כדי לגשת אל Realtime Database, צריך ליצור את firebase::App ולאתחל אותו.
כוללים את קובץ הכותרת של firebase::App:
#include"firebase/app.h"
Android
יוצרים את firebase::App, ומעבירים את סביבת ה-JNI ואת ההפניה jobject לפעילות ב-Java כארגומנטים:
בפלטפורמות למחשבים (Windows, Mac, Linux), FirebaseC++ SDK משתמש ב-REST כדי לגשת למסד הנתונים שלכם. לכן, אתם צריכים להצהיר על האינדקסים שבהם אתם משתמשים באמצעות Query::OrderByChild() במחשב, אחרת המאזינים שלכם ייכשלו.
גרסת Realtime Database למחשב לא תומכת במצב אופליין או בשימור נתונים.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-16 (שעון UTC)."],[],[],null,["# Get Started with Firebase Realtime Database for C++\n\n\u003cbr /\u003e\n\nThe Firebase Realtime Database stores and synchronizes data using a NoSQL cloud\ndatabase. Data is synchronized across all clients in realtime, and remains\navailable when your app goes offline.\n\nBefore You Begin\n----------------\n\nBefore you can use\n[Firebase Realtime Database](/docs/reference/unity/namespace/firebase/database),\nyou need to:\n\n- Register your C++ project and configure it to use Firebase.\n\n If your C++ project already uses Firebase, then it's already registered and\n configured for Firebase.\n- Add the [Firebase C++ SDK](/download/cpp) to your C++ project.\n\n| **Find detailed instructions for these initial\n| setup tasks in\n| [Add Firebase to your C++\n| project](/docs/cpp/setup#note-select-platform).**\n\nNote that adding Firebase to your C++ project involves tasks both in the\n[Firebase console](//console.firebase.google.com/) and in your open C++ project (for example, you download\nFirebase config files from the console, then move them into your C++ project).\n\nCreate a Database\n-----------------\n\n1. Navigate to the **Realtime Database** section of the\n [Firebase console](https://console.firebase.google.com/project/_/database).\n You'll be prompted to select an existing Firebase project.\n Follow the database creation workflow.\n\n2. Select a starting mode for your Firebase Security Rules:\n\n Test mode\n\n : Good for getting started with the mobile and web client libraries,\n but allows anyone to read and overwrite your data. After testing, **make\n sure to review the [Understand Firebase Realtime Database Rules](/docs/database/security)\n section.**\n\n :\n | **Note:** If you create a database in Test mode and make no changes to the default world-readable and world-writeable Rules within a trial period, you will be alerted by email, then your database rules will deny all requests. Note the expiration date during the Firebase console setup flow.\n\n : To get started with the web, Apple, or Android SDK, select testmode.\n\n Locked mode\n\n : Denies all reads and writes from mobile and web clients.\n Your authenticated application servers can still access your database.\n\n3. Choose a location for the database.\n\n Depending on the\n [location of the database](/docs/projects/locations#rtdb-locations), the\n URL for the new database will be in one of the following forms:\n - \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e`.firebaseio.com` (for\n databases in `us-central1`)\n\n - \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e`.`\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e`.firebasedatabase.app`\n (for databases in all other locations)\n\n4. Click **Done**.\n\nWhen you enable Realtime Database, it also enables the API in the\n[Cloud API Manager](https://console.cloud.google.com/projectselector/apis/api/firebasedatabase.googleapis.com/overview).\n\nCreate and Initialize firebase::App\n-----------------------------------\n\nBefore you can access the Realtime Database, you'll need to create and initialize the\n[`firebase::App`](/docs/reference/cpp/class/firebase/app).\n| You only need to initialize firebase::App once, no matter how many Firebase C++ features you use.\n\nInclude the header file for `firebase::App`: \n\n```c++\n#include \"firebase/app.h\"\n``` \n\n### Android\n\n\nCreate the `firebase::App`, passing the JNI environment and a `jobject`\nreference to the Java Activity as arguments: \n\n```c++\napp = ::firebase::App::Create(::firebase::AppOptions(\"APPLICATION NAME\"), jni_env, activity);\n```\n\n### iOS+\n\n\nCreate the `firebase::App`: \n\n```c++\napp = ::firebase::App::Create(::firebase::AppOptions(\"APPLICATION NAME\"));\n```\n\nAccess the firebase::database::Database Class\n---------------------------------------------\n\nThe [`firebase::database::Database`](/docs/reference/cpp/class/firebase/database/database)\nis the entry point for the Firebase Realtime Database C++ SDK. \n\n```c++\n::firebase::database::Database *database = ::firebase::database::Database::GetInstance(app);\n```\n\nIf you have chosen to use public access for your rules, you can proceed to the\nsections on saving and retrieving data.\n\nSetting up Restricted Access\n----------------------------\n\nIf you do not want to use public access you can add Firebase Authentication to your\napp to control access to the database.\n\nNext Steps\n----------\n\n- Learn how to [structure data](/docs/database/cpp/structure-data) for Realtime Database.\n\n- [Scale your data across multiple database\n instances.](/docs/database/usage/sharding)\n\n- [Save data.](/docs/database/cpp/save-data)\n\n- [Retrieve data.](/docs/database/cpp/retrieve-data)\n\n- [View your database in the\n Firebase console.](//console.firebase.google.com/project/_/database/data)\n\n- Prepare to launch your app:\n\n\n - Set up [budget\n alerts](/docs/projects/billing/avoid-surprise-bills#set-up-budget-alert-emails) for your project in the Google Cloud console.\n - Monitor the [*Usage and billing*\n dashboard](//console.firebase.google.com/project/_/usage) in the Firebase console to get an overall picture of your project's usage across multiple Firebase services. You can also visit the [Realtime Database *Usage*\n dashboard](//console.firebase.google.com/project/_/database/usage) for more detailed usage information.\n - Review the [Firebase launch checklist](/support/guides/launch-checklist).\n\nKnown Issues\n------------\n\n- On desktop platforms (Windows, Mac, Linux), the Firebase C++ SDK uses REST to access your database. Because of this, you must [declare the indexes you use](https://firebase.google.com/docs/database/security/#section-defining-indexes) with Query::OrderByChild() on desktop or your listeners will fail.\n- The desktop workflow version of Realtime Database does not support offline or persistence."]]