👨🏻‍💻iOS 공부/iOS & Swift

[iOS] Firebase GoogleService-Info의 파일명 문제

728x90
반응형

Firebase Realtime Database를 연결하기 위해서는 GoogleService-Info.plist를 다운로드 받고 프로젝트에 추가시켜야 한다. 

 

다만 여러 프로젝트를 진행하면서 .plist들도 여러 번 다운로드 받게 되면 파일의 이름이 바뀌게 된다. 

처음에 받을 때는 GoogleService-Info.plist의 파일명이겠지만, 그 이후부터는 GoogleService-Info.plist (1), GoogleService-Info.plist (2)... 이런 식으로 파일명이 중복되지 않게 생성될 것이다. 

 

그대로 프로젝트에 추가하면 당연히 안된다! 기본적으로 AppDelegate에서 실행되는 FirebaseApp.Configure()은 GoogleService-Info.plist를 찾게된다. 하지만 (1)이 붙은 이상 다른 파일이라고 보기에 찾을 수가 없게 된다. 그렇기에 파일명을 직접 가리켜주어 configure할 수 있도록 해야한다. 

 

// AppDelegate

import Firebase

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // 파일명 지정
    let filePath = Bundle.main.path(forResource: "GoogleService-Info (1)", ofType: "plist")!
    let options = FirebaseOptions(contentsOfFile: filePath)
    FirebaseApp.configure(options: options!)
}

 

이렇게 특정 파일명으로 가리키면 문제 없이 Firebase Realtime Database를 사용할 준비를 완료할 수 있다. 

728x90
반응형