firebase-quickstart-ios

repository·main·Indexed 25 days ago

https://github.com/firebase/quickstart-ios

A collection of quickstart samples demonstrating various Firebase APIs on iOS, providing implementation examples for both Swift and Objective-C. Includes guides for A/B Testing, Google Analytics, App Distribution, and Firebase Authentication with multiple identity providers.

Tokens
12.2K
Snippets
19
Records
87
Agent score
85%

What's inside firebase-quickstart-ios

  1. Available Firebase Quickstart Samples

    main

    The repository contains individual quickstart samples for the following Firebase services:

    • A/B Testing
    • Analytics
    • Authentication
    • Remote Config
    • Crashlytics
    • Database
    • Firebase AI
    • Firebase Data Connect
    • Firestore
    • Functions
    • Cloud Messaging
    • Performance
    • Storage
  2. Understand the Firebase Crashlytics SwiftUI Quickstart design

    main

    The Crashlytics SwiftUI Quickstart is a reference implementation for integrating Firebase Crashlytics into SwiftUI-based apps across Apple platforms (iOS, macOS, tvOS, and watchOS).

    Key features demonstrated include:

    • Crash Triggering: A button that triggers a crash to generate reports in the Firebase Console.
    • Custom Crash Data: Demonstrates how to attach custom keys and logs (such as userID, location, and network status) to crash reports to aid debugging.
    • Network Monitoring: Uses Apple's Network framework (NWPathMonitor) to monitor and include device network configuration in crash reports.
    • Cross-Platform Support: Uses SwiftUI and Swift Package Manager to share code across iOS, macOS, tvOS, and watchOS.
  3. Implement Performance Monitoring for Image Tasks

    main

    In the SwiftUI Performance Monitoring Quickstart, Firebase Performance Monitoring is used to track both automatic and custom metrics during image processing workflows (download, classify, saliency map, and upload):

    • Automatic Tracing: Network requests for downloading and uploading images are automatically traced by Performance Monitoring.
    • Custom Traces: Use custom traces to measure the duration of computer vision tasks (e.g., classification and saliency map generation).
    • Custom Attributes: Track metadata such as classification precision and platform type using custom attributes to gain deeper insights into performance across different environments.
  4. Understand the MVVM architecture in the Realtime Database SwiftUI Quickstart

    main

    The Realtime Database Quickstart sample uses the Model-View-ViewModel (MVVM) pattern to separate UI from business logic. This structure is recommended for building scalable SwiftUI applications with Firebase:

    • Model: Represents data and domain logic. Models (e.g., Comment.swift) contain only data and manipulation code, remaining agnostic of networking or storage.
    • View: The user interface implemented with SwiftUI (e.g., ContentView.swift, PostCell.swift).
    • ViewModel: Acts as the 'binder' between the Model and View. ViewModels (e.g., PostViewModel.swift) conform to the ObservableObject protocol and use the @Published property wrapper to publish state changes. They handle user interactions and perform network requests to fetch or write data.
  5. Test an A/B Experiment on a specific device

    main

    To force a specific variant on your development device:

    1. In the Firebase Console, go to your experiment's 'Experiment overview'.
    2. Click the ellipsis (vertical dots) and select Manage test devices.
    3. Run the app on your device/simulator.
    4. Copy the installation auth token printed in the Xcode console.
    5. Paste the token into the text field in the Firebase Console.
    6. Select your desired variant (e.g., Variant A) from the 'Variant' drop-down and click Add.
    7. To apply changes:
      • Tap the Refresh button in the app UI.
      • Or, on iOS 15+, perform a pull-to-refresh gesture.
  6. Configure Firebase App Check debug provider

    main

    This sample uses AppCheckDebugProviderFactory to support Simulators. If you use a different provider in the Firebase Console, you must update the sample code by calling AppCheck.setAppCheckProviderFactory(...) with your specific provider.

    To authorize your simulator:

    1. Run the app and find the generated debug token in the Xcode console (look for <Warning> [AppCheckCore][I-GAC004001] App Check debug token: '<YOUR_TOKEN>').
    2. Copy the token.
    3. In the Firebase Console, navigate to App Check > Apps > Manage debug tokens (via the overflow menu) and register the token.
  7. Enable Developer Mode for Remote Config

    main

    By default, fetching Remote Config data is limited to a few requests per hour. To facilitate testing during development, you can create a Remote Config Setting to enable developer mode, which allows for many more requests per hour.

    Warning: You must remove the developer mode setting before distributing your app to production.

  8. View real-time analytics data in Firebase DebugView

    main

    Once debug logging is enabled and you are interacting with the app, you can view the live stream of analytics data in the Firebase Console:

    1. Navigate to your project in the Firebase Console.
    2. In the vertical menu on the left, select Analytics.
    3. Select DebugView.

    This allows you to see events and user properties being logged by the quickstart in real-time.

  9. Configure Bundle Identifiers for watchOS Crashlytics

    main

    When implementing the Crashlytics Quickstart on watchOS, note that the Bundle Identifier differs from the iOS, macOS, and tvOS targets. To ensure crash logs are correctly generated and viewable in the Firebase Console, you must register a new app in your Firebase project using the specific watchOS Bundle ID.

    • iOS, macOS, tvOS Bundle ID: com.google.firebase.quickstart.CrashlyticsExample
    • watchOS Bundle ID: com.google.firebase.quickstart.CrashlyticsExample.watchkitapp
  10. Set in-app default parameter values

    main

    To avoid needing to define every single parameter in the Firebase Console, set in-app defaults. This allows you to only override specific values remotely.

    In this sample, defaults are set using a .plist file via the setDefaultsFromPlistFileName method. You can also set defaults inline using other setDefaults methods available in the FIRRemoteConfig class.