Add Firebase to Project

Darren Wu
Darren Wu
Aug 28, 2017 · 4 min read

Firebase提供了各式各樣寫APP時常用到的服務

例如使用者認證、資料庫、Notification等等

今天就來記錄一下如何利用CocoaPods將Firebase的加入iOS專案中

首先用google帳號登入來到console點擊新增專案

填入專案名稱跟地點

建立完成就可以看到下面這個畫面

點選加入iOS

接下來打開Xcode找到專案Target下面的Bundle Identifier

填入iOS繫結ID之後點註冊應用程式

接下來就把GoogleService-info.plist下載下來並放到Xcode裡面

接下來就邊看接下來該做的步驟邊按完成到結束吧

CocoaPods的安裝偷懶跳過,跪謝萬能的谷歌大神

CocoaPods安裝好之後就來看看接下來的步驟

先打開終端機移動到Project的目錄下輸入

pod init

然後修改產生出來的podfile內容

這邊範例我直接用vim進行修改,用xcode或其他文字編輯器也可以

直接在終端機Project的目錄下輸入

vim podfile

打開檔案之後按下i進入INSERT MODE

這邊我需要用到Database、Auth、Storage這三項功能

所以輸入

pod ‘Firebase/Database’
pod ‘Firebase/Auth’
pod ‘Firebase/Storage’

輸入完成按下esc離開INSERT MODE

按下Shift + ;輸入wq就會儲存檔案並回到終端機的畫面

修改完podfile就可以來進行pod的安裝拉(如果這時xcode有開可以先關掉)

一樣在終端機Project的目錄下輸入pod install

等他跑完就會發現目錄下多了一個projectName.xcworkspace檔案

點兩下這檔案打開xcode就會發現多了個pod的資料夾

裡面就包含了剛剛安裝的pod

最後再回到AppDelegate.swift修改一下

先import Firebase的套件

然後在didFinishLaunchingWithOptions這個function內加上

FIRApp.configure()

套件的安裝就到這邊,接下來就可以在專案裡需要Firebase的地方

import Firebase

進行使用嘍

彼得潘的 Swift iOS App 開發教室

學習 Swift iOS App 開發的學生作品集

)

Darren Wu

Written by

Darren Wu

彼得潘的 Swift iOS App 開發教室

學習 Swift iOS App 開發的學生作品集

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade