About the Download

Ti.Firebase

Ti.Firebase is an iOS Hyperloop wrapper of the Firebase SDK.

It provides the following functionalities:

If you are not familiar with Firebase we totally recommend you having a look at their website.

With Titanium and Hyperloop you can embed this module into your project and with a few lines of code you will be able to create an integration between your Firebase backend and your mobile app. Firebase is well known because it makes the mobile developer life easier by providing an easy-to-use backend solution hosted by Google.

What you’ll find in this module and app

Yes, you’ve read it right. We thought that just shipping a module would not be enough to show you the benefits of using Firebase in your apps, and that’s why we are providing a complete app that demonstrates what the Firebase SDK is capable of.

Authentication

The example app checks if the provided user exists or not. If the user already exists he will be automatically logged in. If it doesn’t Firebase will automatically and transparently create it in the backend for you.

sep-23-2016-15-59-51

Meanwhile in the Firebase Console…

sep-23-2016-15-50-42

Real Time Database

Ti.Firebase creates an observer on the ‘Cars‘ table to observe every single change in the Database. In the following example we have created some data directly through Firebase Console. Check out how quickly the app sees the changes in the database. The same happens if you delete something the database. ?

sep-23-2016-16-07-19

 

 

 

 

 

 

 

 

With Ti.Firebase you can also create and delete data through the app.

sep-23-2016-16-22-01

sep-23-2016-16-24-48

Firebase Cloud Messaging (Push Notifications)

With Ti.Firebase you’re able to send Push Notification messages through Firebase Console.

Google is pushing developers to start using FCM instead of the usual GCM to send Push Notifications.
Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! More details in their FAQ.

sep-23-2016-16-29-48

On a real device

img_2095

README

These instructions are being shipped with the module, so you can check later on your README file.

LoopModules – Ti.Firebase

This HyperLoop module/app allows you to use the native Firebase SDK.
The main features of this SDK are:

  • Authentication
    • User account creation
    • Sign In
    • Sign Off
  • RealTime Database
    • Creating and deleting data
    • Fetching data
  • Firebase Cloud Messaging (Push Notifications)
    • Register for Push Notifications
    • Register group of users
    • Send Push Notifications through Firebase Console

1 – Hyperloop

This project uses HyperLoop. We recommend you to read the basics of HyperLoop in the links below before exploring more of this technology.
iOS: Hyperloop_for_iOS-Programming_Guide
Android: Hyperloop_for_Android_Programming_Guide

HyperLoop does a pretty good job in allowing you to use Objective-C / Swift with Javascript syntax, but that doesn’t mean that you won’t need to learn Objective-C / Swift if you want to customize the module / create your own. In the long run that will make your job easier.

2 – Firebase Requirements

We recommend you to read the Firebase documentation. You should know how to set up a Firebase project and how Firebase works before doing anything else.

  • The first thing you should do is create a Firebase project. 
  • Open the project you just created and create a new app for it. You’ll need one firebase app for each platform you intend to support
  • Open your app settings and look for a button that lets you download a file called GoogleService-Info.plist. This file contains configuration details such as keys and identifiers for the services you’ll enable.
  • In the menu (left hand side of the screen) click on Auth
  • In the new window that opened you will need to enable the login through Email/Password. To do that, open the ‘SIGN-IN METHOD’ tab and enable the option ‘Email/Password’

If you want to use Push Notifications, you should also enable the Cloud Messaging System:

  • Go to your Firebase project dashboard and open your app’s settings;
  • Open the tab Cloud Messaging;
  • Upload your Development APN certificate and the Production APN certificate. You should be familiar with this if you ever implemented push notifications on your app before. If not, take a look at Appcelerator’s Push Notification tutorial.

3 – Environment setup

This module was tested and developed with the following environment:

  • CocoaPods 1.0.1
  • Titanium SDK 6.0.0.v20161101155110
  • HyperLoop 2.0.0
  • XCode 8.1

4 – Usage

  • Change the App GUID in the provided tiapp.xml file to your original App GUID
  • Place the GoogleService-Info.plist (explained in the section Firebase requirements) inside the folder “src”. It’s located in the root folder of the provided project.
  • Simply run the project provided in this download and you should be all set to start using Firebase!

In this download you’ll find a complete Alloy project that uses Firebase to:

  • Enable authentication with social medias and e-mail
  • Register to Push Notifications channels
  • Communicate with a Real Time Database

Available functions

  • Firebase Core
    • configure -> Configures a default Firebase app
    • getAllApp -> Returns the set of all extant FIRApp instances, or nil if there is no FIRApp instance
    • getAppWithName -> Returns a previously created FIRApp instance with the given name, or nil if no such app exists
    • getDefaultOptions -> Returns the default options
    • initWithOptions -> Initializes a customized instance of FIROptions with keys
  • Firebase Auth
    • createUser -> Creates and, on success, signs in a user with the given email address and password
    • signOut -> Signs out the current user
    • loginUser -> Signs in using an email address and password.
    • currentUser -> Get the current user
  • Firebase Database
    • connectDatabase -> Gets a FIRDatabaseReference for the root of your Firebase Database.
    • getAppForDatabase -> The FIRApp instance to which this FIRDatabase belongs
    • createCar -> Creates a new ‘Car’ in the RealTime Database
    • deleteCar -> Deletes a specific ‘Car’ in the RealTime Database
    • getCars -> Create an observer on the RealTime Database where it triggers every time some ‘Car’ data is changed on the database
  • Firebase Messaging (FCM – Firebase Cloud Messaging)
    • getToken -> Gets a registration token from FirebaseInstanceID, which authorizes an app server to send messages to an app instance
    • connectToFcm -> Create a FIRMessaging data connection which will be used to send the data notifications send by your server
    • subscribeToTopic -> Asynchronously subscribes to a topic
    • unsubscribeFromTopic -> Asynchronously unsubscribe to a topic
    • disconnect -> Disconnect the current FIRMessaging data connection
  • Appc Push Notifications Framework
    • A JS lib to initialize the push notifications process.

Support

One of the things we want to offer you as a reward for joining LoopModules is the ability to contact us to discuss and get help with problems that you may come across.
We’ve tested this module a lot of times and we want to deliver something that will work for everyone (as long as the environments are the same, e.g. SDK, HL version, and so on).
If you come across one of the following:

  • Bugs
  • Suggestions
  • Issues while compiling this module

Feel free to contact us at contact@loopmodules.com.