• A Quick Guide to Firebase: An Innovation in Mobile App Development

    180405_quick_guide_firebase_v3

    Firebase is a Backend-as-a-Service (BaaS) for mobiles and web to build powerful apps. It was launched by Google to support web-based backend. Initially developed as a YC11 startup, it further developed into a next-generation app on Google Cloud Platform.

    What is the Purpose of Firebase?

    Firebase aims at offering a real-time database as well as backend as a service. It stores JSON data in a real-time database. BaaS service provides application developers an application programming interface (API) enabling app data to coordinate via clients and stored on Firebase cloud messaging server.

    If there’s a change in the database, that is also synchronized across the clients and device using the same database.

    Firebase liberates developers to focus on making impressive client experiences. You do not have to manage servers or write APIs. Firebase is just like your server, your API, and your data store, where everything that is written can be modified or changed as per your needs.

    How to Create a Firebase Account?

    Firstly, create a Firebase account by visiting “https://console.Firebase.googl.com”. By clicking on the plus icon, you can add your project. You can even create a demo account where authenticated users can add or delete the products. Secondly, you can upload the picture of a client to “storage”. With this, you will be able to see the users present online.

    After adding projects in the Firebase Google console, you will be navigated to the dashboard. Here, you will see a list in the dashboard where the features of the dashboard are mentioned in the left. Further, a small description is also given related to projects.

    Here’s a List of the Features of Firebase:

    Real-time Database

    A real-time database is a database with no Structured Query Language (SQL). Here, data is stored and synced as a JSON design in real time to every customer connected. All the customers using Android, iOS, or JavaScript shares just a single database. Changes made in the client’s application is synchronized with the real-time database automatically, which works in the offline mode.

    
    ref = Database.database().reference(withPath: “grocery-items”)
    

    Now, we create the new example for the new product item

     
    let productItemRef = self.ref?.child(text.lowercased())
    productItemRef?.setValue([
    "name": text,
    "addedByUser": self.user.email,
    "completed": false
    ]) 
    

    It will add or synchronize the item to Firebase console-like as shown below.

    Next step is to reload and upload the view. While adding, updating, or deleting the product into the database, the initialized closure will always give a call.

    
    ref?.queryOrdered(byChild: "completed").observe(.value, with:
    { snapshot in 
    var newItems: [GroceryItem] = []
    for item in snapshot.children {
    let groceryItem = GroceryItem(snapshot: item as!
    DataSnapshot)
    newItems.append(groceryItem)
    } 
    self.items = newItems
    self.tableView.reloadData()
    })
    

    Two more products are added to this observer we got every value even the new or updated one and then we reloaded the table.

    
    queryOrdered(byChild: "completed") 
    

    key helps us sort the values according to “completed key”.

    Hosting

    Hosting is considered as a simple process in the Firebase app development. Three new features are involved here – custom domain support free, Global CDN, and Auto-provisioned SSL certs. You can easily deploy the applications once the Firebase CLI is installed and set up. It is easy to host your site or app.

    
    # install the CLI
    npm install -g Firebase-tools
    # login
    Firebase login
    # start a project
    Firebase init
    # run locally
    Firebase serve
    # DEPLOY!
    Firebase deploy
    

    Authentication

    Many applications require users’ identity to fetch and save the important information related to users. Firebase Authentication gives backend services, which is easy to use. Also, instant libraries are provided to validate clients to your application.

    It supports confirmation of your App’s users through the following methods:

    • Google
    • Email & Password
    • Phone numbers
    • Facebook
    • Twitter

    With the help of the Firebase Authentication, one can easily build a secure system, and can improve the sign-in and onboarding experience for end users.

    Given below is the code to handle social authentication with the help of new SDK:

    
    // grab the twitter auth provider
    var provider = new Firebase.auth.TwitterAuthProvider();
    // do the login
    Firebase.auth().signInWithPopup(provider).then(function(result) {
      // twitter token and secret you can use to contact the twitter api
      var token  = result.credential.accessToken;
      var secret = result.credential.secret;
      // user info
      var user = result.user;
    }).catch(function(error) {
      // blah blah errors
    });
    

    Storage

    You can upload or download the files such as video, photos, or pdf into google cloud storage. Firebase offers a simple and quick framework for cloud storage. You need to create the instance first for storage as given below:

    
    func uploadImageForUser(image: UIImage) {
    guard let imageData = UIImageJPEGRepresentation(image, 0.8)
    else { return }
    let imagePath = Auth.auth().currentUser!.uid +
    "/\(Int(Date.timeIntervalSinceReferenceDate *
    1000)).jpg" 
    let metadata = StorageMetadata()
    metadata.contentType = "image/png"
    Storage.storage().reference().child(imagePath).putData(imageDat
    a, metadata: metadata) { (metadata, error) in
    if let error = error {
    } 
    print("Error uploading: \(error)")
    return 
    let changeRequest =
    Auth.auth().currentUser?.createProfileChangeRequest()
    changeRequest?.photoURL = metadata?.downloadURL()
    changeRequest?.commitChanges { (error) in
    print("User Changed")
    } 
    } 
    }
    

    Analytics:

    Firebase Google Analytics is a free and unlimited analytics solution. It offers you unlimited reporting for up to 500 different events that can be defined using the Firebase SDK. These analytics reports helps in knowing how your users behave thus helping you make informed decisions related to app marketing and performance optimizations.

    Notification:

    Using Firebase cloud messaging (FCM), a client receives notification on the app whenever a new mail or any data is synced. A notification messages can be send to drive user retention and re-engagement.

    Dynamic Links:

    The active links are the links or the url which can work as per your requirements. You can create the link via the Firebase console or through the application, which have lots of hidden features and the data. If the user clicks on the link via mobile or website, it will direct you to the related content in your local app or site. If the application is not installed, then you will be directed either to the play store or to the App store. Once the installation is done, you will able to open the coveted page or link.

    Remote Configuration Variables for Apps

    Remote configuration instantly allows the developers to change the functionality of the App without uploading the new version. This means that you do not have to wait for a long process to get new data for your applications. Below are the steps showing how to use Remote Configuration in your app:

    • Include Firebase to your app
    • Get the Remote Configuration singleton object
    • Set in-app default parameter values
    • Get parameter values to use in your app
    • Set parameter values accordingly in the Remote Config service
    • Fetch and activate values accordingly from the Remote Config service

    AdMob

    AdMob is an easy way to monetize mobile apps with targeted in-app advertising. With the help of Google Analytics, one can drive installs, gain deep insights into ad conversions, and run targeted ad campaigns to engage the user base for Firebase audience. While linking Firebase and AdWords, you get access to controlling tools. This helps you to see how your AdWords investment drives app installs and in-app actions. You can even export and import the audience and evet list from Analytics to AdWords.

    Conclusion

    Firebase is an impressive far-reaching platform for mobile app development that streamlines various tasks producing quality software solutions. It will surely give a tough competition to companies providing web services because it is backed by Google.

    We hope the above article has answered to your queries on Firebase; however, if you still have any other queries or are looking for digital assistance, you can email us at info@netsolutions.com or write in the comments section.

    Amit Manchanda

    About the Author

    Amit Manchanda is working as Project Lead at Net Solutions and has over 9 years of experience in technologies like ASP, Adobe Flex and Android. He has been part of SME (Subject Matter Expert) Group for RIA applications. He has good understanding of analyzing the technical need/problem of client and providing them the best solution. He enjoys interacting with his team & is passionate about his work. In his free time he loves to listen music, watch Cricket and play with his daughter.

    Comments

     
     

    Shahraz Khan

    2:32 PM, May 31, 2018

    Hello Amit,
    Really firebase is an innovation in mobile app development. Firebase liberates developers to focus on making impressive client experiences. You do not have to manage servers or write APIs. Firebase is just like your server, your API, and your data store, where everything that is written can be modified or changed as per your needs.
    Thnaks

    Susheel

    3:41 PM, Apr 20, 2018

    Great information shared you have in this blog post. Thanks for sharing.

    Susheel

    3:39 PM, Apr 20, 2018

    Great information shared you have in this blog post. Thanks for sharing.



    get in touch

    Ready to discuss your requirements?

    Request Free Consultation