نصب و راه اندازی & راه اندازی بر روی پلتفرم های اپل
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Firebase Realtime Database یک پایگاه داده میزبان ابر است. داده ها به صورت JSON ذخیره می شوند و در زمان واقعی با هر مشتری متصل همگام سازی می شوند. وقتی برنامههای متقابل پلتفرمی را با کیتهای توسعه نرمافزار Android، iOS، و جاوا اسکریپت میسازید، همه مشتریان شما یک نمونه Realtime Database را به اشتراک میگذارند و بهطور خودکار بهروزرسانیها را با جدیدترین دادهها دریافت میکنند.
Firebase Realtime Database در تمام پلتفرم های اپل از جمله iOS، macOS، macOS Catalyst، tvOS و watchOS در دسترس است. برای کلیپ های برنامه در دسترس نیست. دستورالعملهای راهاندازی در این صفحه در مثالهای خاص به iOS اشاره میکنند، اما عمومی هستند و برای هر هدف پلتفرم اپل کار میکنند.
برنامه خود را به پروژه Firebase خود در کنسول Firebase اضافه کنید.
یک پایگاه داده ایجاد کنید
به بخش Realtime Databaseکنسول Firebase بروید. از شما خواسته می شود که یک پروژه Firebase موجود را انتخاب کنید. گردش کار ایجاد پایگاه داده را دنبال کنید.
یک حالت شروع برای Firebase Security Rules خود انتخاب کنید:
حالت تست
برای شروع کار با کتابخانه های موبایل و کلاینت وب خوب است، اما به هر کسی اجازه می دهد داده های شما را بخواند و بازنویسی کند. پس از تست، حتما قسمت Understand Firebase Realtime Database Rules را مرور کنید.
برای شروع کار با وب، اپل یا اندروید SDK، حالت تست را انتخاب کنید.
حالت قفل شده
همه خواندن و نوشتن از مشتریان تلفن همراه و وب را رد می کند. سرورهای برنامه تأیید شده شما همچنان می توانند به پایگاه داده شما دسترسی داشته باشند.
مکانی را برای پایگاه داده انتخاب کنید.
بسته به موقعیت پایگاه داده ، URL پایگاه داده جدید به یکی از اشکال زیر خواهد بود:
DATABASE_NAME .firebaseio.com (برای پایگاههای داده در us-central1 )
DATABASE_NAME . REGION .firebasedatabase.app (برای پایگاههای داده در همه مکانهای دیگر)
روی Done کلیک کنید.
هنگامی که Realtime Database فعال می کنید، API را در Cloud API Manager نیز فعال می کند.
Firebase Realtime Database به برنامه خود اضافه کنید
برای نصب و مدیریت وابستگی های Firebase از Swift Package Manager استفاده کنید.
در Xcode، با باز بودن پروژه برنامه، به File > Add Packages بروید.
هنگامی که از شما خواسته شد، مخزن SDK پلتفرم های Apple Firebase را اضافه کنید:
https://github.com/firebase/firebase-ios-sdk.git
کتابخانه Realtime Database را انتخاب کنید.
پرچم -ObjC را به بخش Other Linker Flags تنظیمات ساخت هدف خود اضافه کنید.
پس از اتمام، Xcode به طور خودکار شروع به حل و دانلود وابستگی های شما در پس زمینه می کند.
Realtime Database Security Rules پیکربندی کنید
Realtime Database یک زبان قواعد اعلامی را ارائه می دهد که به شما امکان می دهد نحوه ساختار داده های شما، نحوه فهرست بندی و زمان خواندن و نوشتن داده های شما را تعریف کنید.
Firebase Realtime Database را تنظیم کنید
قبل از ایجاد یا استفاده از هر مرجع برنامه Firebase، باید Firebase را مقداردهی اولیه کنید. اگر قبلاً این کار را برای یکی دیگر از ویژگی های Firebase انجام داده اید، می توانید از این مرحله رد شوید.
ماژول FirebaseCore را در UIApplicationDelegate خود و همچنین هر ماژول Firebase دیگری که نماینده برنامه شما استفاده میکند، وارد کنید. به عنوان مثال، برای استفاده از Cloud Firestore و Authentication :
یک نمونه اشتراکگذاری شده FirebaseApp در روش application(_:didFinishLaunchingWithOptions:) پیکربندی کنید:
SwiftUI
// Use Firebase library to configure APIsFirebaseApp.configure()
سویفت
// Use Firebase library to configure APIsFirebaseApp.configure()
هدف-C
// Use Firebase library to configure APIs[FIRAppconfigure];
اگر از SwiftUI استفاده میکنید، باید یک نماینده برنامه ایجاد کنید و آن را از طریق UIApplicationDelegateAdaptor یا NSApplicationDelegateAdaptor به ساختار App خود متصل کنید. همچنین باید swizzling نمایندگی برنامه را غیرفعال کنید. برای اطلاعات بیشتر، دستورالعمل های SwiftUI را ببینید.
SwiftUI
@mainstructYourApp:App{// register app delegate for Firebase setup@UIApplicationDelegateAdaptor(AppDelegate.self)vardelegatevarbody:someScene{WindowGroup{NavigationView{ContentView()}}}}
یک مرجع برای پایگاه داده خود ایجاد کنید و مکانی را که می خواهید در آن بنویسید را مشخص کنید.
تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-15 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Installation & Setup on Apple platforms\n\n\u003cbr /\u003e\n\nThe Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON\nand synchronized in realtime to every connected client. When you build\ncross-platform apps with our Android, iOS, and JavaScript SDKs, all of your\nclients share one Realtime Database instance and automatically receive updates with\nthe newest data.\n\nFirebase Realtime Database is available on all Apple platforms, including iOS,\nmacOS, macOS Catalyst, tvOS, and watchOS. It is not available for App Clips.\nThe setup instructions in this page reference iOS in specific examples, but are\ngeneric and work for any Apple platform target.\n\nPrerequisites\n-------------\n\n1. [Install the Firebase SDK](/docs/ios/setup).\n2. Add your app to your Firebase project in the [Firebase console](//console.firebase.google.com/).\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\nAdd Firebase Realtime Database to your app\n------------------------------------------\n\nUse Swift Package Manager to install and manage Firebase dependencies.\n| Visit [our installation guide](/docs/ios/installation-methods) to learn about the different ways you can add Firebase SDKs to your Apple project, including importing frameworks directly and using CocoaPods.\n\n1. In Xcode, with your app project open, navigate to **File \\\u003e Add Packages**.\n2. When prompted, add the Firebase Apple platforms SDK repository: \n\n```text\n https://github.com/firebase/firebase-ios-sdk.git\n```\n| **Note:** New projects should use the default (latest) SDK version, but you can choose an older version if needed.\n3. Choose the Realtime Database library.\n4. Add the `-ObjC` flag to the *Other Linker Flags* section of your target's build settings.\n5. When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.\n\nConfigure Realtime Database Security Rules\n------------------------------------------\n\nThe Realtime Database provides a declarative rules language that allows you to\ndefine how your data should be structured, how it should be indexed, and when\nyour data can be read from and written to.\n| **Note:** By default, read and write access to your database is restricted so only authenticated users can read or write data. To get started without setting up [Authentication](/docs/auth), you can [configure your rules for public access](/docs/rules/basics#default_rules_locked_mode). This does make your database open to anyone, even people not using your app, so be sure to restrict your database again when you set up authentication.\n\nSet up Firebase Realtime Database\n---------------------------------\n\nYou must initialize Firebase before any Firebase app reference is created or\nused. If you have already done this for another Firebase feature, you can skip\nthis step.\n\n1. Import the `FirebaseCore` module in your `UIApplicationDelegate`, as well as any other [Firebase modules](/docs/ios/setup#available-pods) your app delegate uses. For example, to use Cloud Firestore and Authentication: \n\n #### SwiftUI\n\n ```swift\n import SwiftUI\n import FirebaseCore\n import FirebaseFirestore\n import FirebaseAuth\n // ...\n \n ```\n\n #### Swift\n\n ```swift\n import FirebaseCore\n import FirebaseFirestore\n import FirebaseAuth\n // ...\n \n ```\n\n #### Objective-C\n\n ```objective-c\n @import FirebaseCore;\n @import FirebaseFirestore;\n @import FirebaseAuth;\n // ...\n \n ```\n2. Configure a [`FirebaseApp`](/docs/reference/swift/firebasecore/api/reference/Classes/FirebaseApp) shared instance in your app delegate's `application(_:didFinishLaunchingWithOptions:)` method: \n\n #### SwiftUI\n\n ```swift\n // Use Firebase library to configure APIs\n FirebaseApp.configure()\n ```\n\n #### Swift\n\n ```swift\n // Use Firebase library to configure APIs\n FirebaseApp.configure()\n ```\n\n #### Objective-C\n\n ```objective-c\n // Use Firebase library to configure APIs\n [FIRApp configure];\n ```\n3. If you're using SwiftUI, you must create an application delegate and attach it to your `App` struct via `UIApplicationDelegateAdaptor` or `NSApplicationDelegateAdaptor`. You must also disable app delegate swizzling. For more information, see the [SwiftUI instructions](/docs/ios/learn-more#swiftui). \n\n #### SwiftUI\n\n ```swift\n @main\n struct YourApp: App {\n // register app delegate for Firebase setup\n @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate\n\n var body: some Scene {\n WindowGroup {\n NavigationView {\n ContentView()\n }\n }\n }\n }\n \n ```\n4. Create a reference to your database and specify the location you want to write to. **Important** : To get a reference to a database other than a `us-central1` default database, you must pass the database URL to `database()` (or for Objective-C `databaseWithURL`). For a `us-central1` default database, you can call `database()` (or `database`) without arguments.\n |\n | You can find your Realtime Database URL in the *Realtime Database* section of the\n | [Firebase console](//console.firebase.google.com/). Depending on the\n | [location of the database](/docs/projects/locations#rtdb-locations),\n | the database URL will be in one of the following forms:\n | - `https://`\u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e`.firebaseio.com` (for databases in `us-central1`)\n | - `https://`\u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e`.`\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e`.firebasedatabase.app` (for databases in all other locations)\n\n ### Swift\n\n **Note:** This Firebase product is not available on the App Clip target. \n\n ```swift\n var ref: DatabaseReference!\n\n ref = Database.database().reference()\n ```\n\n ### Objective-C\n\n **Note:** This Firebase product is not available on the App Clip target. \n\n ```objective-c\n @property (strong, nonatomic) FIRDatabaseReference *ref;\n\n self.ref = [[FIRDatabase database] reference];\n ```\n\nNext Steps\n----------\n\n- Learn how to [structure data](/docs/database/ios/structure-data) for Realtime Database.\n\n- [Scale your data across multiple database\n instances.](/docs/database/usage/sharding)\n\n- [Read and write data.](/docs/database/ios/read-and-write)\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 - Enable [App Check](/docs/app-check/ios) to help ensure that only your\n apps can access your databases.\n\n - Set up [budget\n alerts](/docs/projects/billing/avoid-surprise-bills#set-up-budget-alert-emails)\n for your project in the Google Cloud console.\n\n - Monitor the [*Usage and billing*\n dashboard](//console.firebase.google.com/project/_/usage)\n in the Firebase console to get an overall picture of your project's\n usage across multiple Firebase services.\n You can also visit the [Realtime Database *Usage*\n dashboard](//console.firebase.google.com/project/_/database/usage) for more\n detailed usage information.\n\n - Review the [Firebase launch checklist](/support/guides/launch-checklist)."]]