Firebase and AdMob iOS Support

From RAD Studio
Jump to: navigation, search

RAD Studio introduces two new features specific to the iOS platform related to Google Firebase support and the Google AdMob. Between them you can find:

  • The ability to receive push notifications from the Firebase Cloud Messaging (FCM) service.
  • The ability to present advertising banners from the AdMob service, including the integration with analytics capabilities from the Firebase Analytics service.

Both features have a dependency on the Firebase SDK for iOS, delivered via GetIt.

As the Firebase Cloud Messaging service uses the Apple Push Notification service (APNs) to send push notifications to an iOS application, you need to:

  • Create a provisioning profile that enables the Push Notifications capability.
  • Create an APNs authentication key to allow your iOS application to use the FCM service.

Create a provisioning profile to enable push notifications in your iOS application

To allow your iOS application to receive push notifications, you need to create and install a provisioning profile on your macOS device.

If you have an existing provisioning profile, you can use it instead of creating a new one. Otherwise, follow the steps below:

  1. Browse the https://developer.apple.com web page.
  2. Login with your Apple Developer credentials.
  3. Select the Certificates, IDs & Profiles menu.
    =link
  4. On the Identifiers menu, click the “+” button to add a new identifier.
    =link
  5. Select the App IDs option and click Continue.
    =link
  6. Select the App IDs option and click Continue.
    =link
  7. Enter a description and a bundle identifier.
    =link
  8. Enable the Push Notifications capability and click Continue.
    =Link
  9. Confirm the application identifier and click Register.
    =link
  10. On the Profiles tab, click the “+” button to add a new Provisioning Profile.
    =Link
  11. Select the iOS App Development option and click Continue.
    =Link
  12. Select the application identifier registered before and click Continue.
    =link
  13. Select the development certificate(s) to include in the provisioning profile, and click Continue.
    =Link
  14. Select the test device(s) to include in the provisioning profile, and click Continue.
    =Link
  15. Enter a provisioning profile name and click Generate.
    =link
  16. Click Download and install the provisioning profile on the macOS machine.
    =link
Note: This documentation page supposes that your application is under the development cycle. For the distribution cycle, you have to create a similar provisioning profile to allow submitting your application to the App Store.

Create an APNs authentication key

To allow your Firebase project to send push notifications to your application through the Apple Push Notification service (APNs), you need to create an APNs authentication key. To do so, follow the steps below.

Prepare your iOS application to use the Firebase Cloud Messaging service

In RAD Studio, the new FMX.PushNotification.FCM.iOS unit implements the support for the iOS platform to push notifications from the Firebase Cloud Messaging service. The FCM support relies on the APIs from the System.PushNotification unit, therefore, is possible to use the same code for Android and iOS platforms.

Note: The Firebase Cloud Messaging support for the Android platform was added in the 10.3.2 release.

Create a Firebase project

  1. Browse the https://console.firebase.google.com web page.
  2. Click +Add Project.
    =link
  3. Enter a name for your project and click Continue.
    =link
  4. Consider disabling the Google Analytics integration at this moment and click Continue. It can be enabled later.

iOS Project prerequisites

To add Firebase to your iOS Project make sure to meet the following prerequisites:

  • Install Xcode 11.0 or later and CocoaPods 1.9.0 or later.
  • The project must target iOS 10 or later.
  • An Apple Push Notification Key for your Apple Developer account.
  • Enable Push Notifications in XCode under App > Capabilities.
  • Sign in to FireBase using your Google account.

Add Firebase to you iOS Project

Follow the next steps to add firebase to your iOS project:

  1. Create a Firebase project to connect your iOS application.
  2. Register your application with FireBase.
  3. Add a Firebase configuration File.
  4. Add Firebase SDKs to your app.
  5. Add the APNs authentication key.
  6. Initialize Firebase in your app.
  7. Register your application for remote notification.
Note: For more information about Firebase projects visit: Add Firebase to your iOS project, Create a Firebase project

Access the registration token

Firebase Cloud Messaging (FCM) SDK generates a registration token by default. This token allows you to send targeted notifications to any particular instance of the iOS app. Also, Firebase Cloud Messaging (FCM) SDK retrieves a new or existing token during the application launch and whenever the token is updated or invalidated.

Firebase Mobile Ads

Active the Firebase advertising by dropping the FirebaseBannerAd component on a form.

Attention: The FirebaseBannerAdcomponent is an iOS-specific feature.
Note: To activate the Firebase advertising controls set the target platforms to an iOS platform.

Firebase Banner Add

To finish the configuration, set the following runtime properties:

  • AdSize: TFirebaseBannerAdSize
  • AdUnitID: string
  • Model: TCustomFirebaseBannerAdModel
  • TestMode: Boolean

Also, you can configure the LoadAd key method and some event handlers:

  • OnDidDismissScreen
  • OnDidFailToReceiveAd
  • OnDidReceiveAd
  • OnWillDismissScreen
  • OnWillLeaveApplication
  • OnWillPresentScreen

For more information check the FMX.Advertising.Firebase unit.

Firebase SDK via GetIt

To build applications using Firebase on iOS you need to install on your development machine the Firebase SDK provided by Google.

This installation will be provided soon via a specific GetIt package, check the GetIt package manager for availability.

Alternatively, you can accept the license and download the SDK directly from Google see the main Firebase SDK for iOS on the GitHub site:

on a specific download link such as:

You can also get the latest version at

Warning: Downloading a higher version than the 6.18.0 for iOS Firebase SDK is not recommended, since RAD Studio cannot guarantee that the interfaces remain compatible.