Since the official Parse shutdown, many people are looking for alternatives. Google established Firebase as one such option for your web-based backend. In deze tutorial zullen we exploreren hoe te bouwen een iOS-app die gebruik maakt van Google Firebase als backend.
My name is Bernhard Götzendorfer and I'm currently interning at Cocoanetics. I've spent some time working with Google's Firebase and since I wanted to start blogging, I will take this opportunity and walk you through the steps to create a simple iOS App using Firebase.
Then click Add App ]. This will generate a GoogleService-Info.plist which downloads.
- Open your Terminal, navigate to the project location. One quick way to do that is to enter cd and then drag the project folder onto the terminal window.
- Create a new Podfile by typing pod init .
Note: You need to close your Xcode project and instead open the newly generated xcworkspace
In other words, you will not be able to compile because only the work space has the necessary pod references.
Firebase Code Setup
In AppDelegate.swift we add an import for the Firebase module and call to the configure function within didFinishLaunchingWithOptions as shown below.
Firebase Authentication Rules
As the last step for configuring Firebase, we need to modify the authentication rules in the Firebase console. If you still see the Add Firebase to my iOS App popup, then close that by clicking on the X.
Click on the Database tab on the left side and click on Rules at the top. Modify the rules to look like shown in the screenshot below:
For this tutorial we will not need any more elaborate authentication, so we just make read access public. For more information about this refer to https://firebase.google.com/docs/database/security/quickstart.
Firebase setup is now complete!
Building the Messaging App
With Firebase setup now complete,
Right-click on the FirebaseDemo folder in project navigator and select New File .
Create a Cocoa Touch Class – Subclass of UIViewController named AddViewController .
Repeat that step but with Subclass or UITableViewController named MessageTableViewController .
And our last one: Choose Swift File and name it Message .
Xcode will add .swift to all these new files. Your file structure should look like this:
Go to your Main.storyboard and delete your current view controller.
Search for Table View Controller in the object browser (bottom right of the inspector panel) and drag it into your storyboard.
Select the new Table View Controller and in the Menu Bar at the top select Editor -> Embed -> Navigation Controller. This creates a new navigation controller that has the table view controller as root.
In the attribute inspector for the new navigation controller, check "Is Initial View Controller" – this is our App's starting point.
Search for a Bar Button Item on the bottom right and insert it at the top right of the navigation bar on the table view controller. Change the System Item to Add.
Drag a new View Controller onto the canvas.
Control + drag the plus button to the view controller and select the Show option in the popup.If you now click on the + in your app, it will navigate you to the view controller.
- Button View