Notice
Recent Posts
Recent Comments
Link
관리 메뉴

김종권의 iOS 앱 개발 알아가기

[iOS - swift] Firebase 연동 방법, FirebaseSDK, GoogleService-info.plist 본문

iOS 응용 (swift)

[iOS - swift] Firebase 연동 방법, FirebaseSDK, GoogleService-info.plist

jake-kim 2020. 11. 21. 13:55

Firebase를 쓰는 이유

  • REST API를 쓸 때, gRPC와 같이 stream으로 받고 싶은 경우 구독하면서 쓰는 Firestore존재
  • DB를 쓸 때 따로 서버를 만들지 않고 Firebase/Database를 사용 가능
  • 앱에서 나타나는 오류 분석을 Firebase에 전송: 'Firebase/Crashlytics'
  • 앱 이용자 분석:  'Firebase/Analytics'

Xcode에서 Firebase라는 프레임워크가 서버의 Firebase에 연동하는 원리

Firebase에서 앱 번들을 주고 앱을 등록하면, "GoogleService-info.plist"라는 파일을 다운받을 수 있게 해주는데,

이 파일을 프로젝트 안에 포함시켜 놓으면 연동 완료

Firebase에 앱 등록

console.firebase.google.com/여기에서 로그인 후 

  • 프로젝트 생성

  • 프로젝트 생성 후, 아래 화면에서 iOS 버튼 선택

  • iOS번들 입력

  • 추가적으로 계속 입력해도 되고, 앱 등록만 한 후 아래 화면에서도 'GoogleService-info.plist'파일도 다운로드 선택 가능

  •  GoogleService-info.plist파일 추가: 다운받아서 Xcode에 추가 (단, 프로젝트의 최상위 root에다 추가해야함 - Firebase가이드)

Firebase프레임워크 의존성 추가

pod 'Firebase/Core'

Firebase에 연결하는 코드를 AppDelegate에 추가

  • FirebaseApp.configure()추가 : GoogleServiec-info.plist파일에 File I/O하는 기능 (configure이 잘못 되어 있다면 exception을 발생 시킴)
//
//  AppDelegate.swift
//  FirebaseTest
//
//  Created by 김종권 on 2020/11/21.
//

import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()

        return true
    }

...

 

Comments