source

기본 앱이 아직 구성되지 않았습니다.

factcode 2023. 6. 8. 22:37
반응형

기본 앱이 아직 구성되지 않았습니다.

저는 제 앱을 파이어베이스의 새로운 버전으로 업그레이드하려고 합니다.저는 설정 가이드를 살펴보고 새로운 구문과 일치하도록 제 모든 코드를 편집했습니다.하지만 앱을 실행하면 이 두 가지 오류가 발생합니다.

The default app has not been configured yet.
Terminating app due to uncaught exception 'MissingDatabaseURL', reason: 'Failed to get FIRDatabase instance: FIRApp object has no databaseURL in its FirebaseOptions object.'

있습니다FIRApp.configure()AppDelegate에서 Google Services-Info.plist를 프로젝트로 가져옵니다.또한 리스트에는 올바른 정보가 모두 포함되어 있습니다.이 문제에 부딪히거나 해결 방법을 아는 사람이 있습니까?

문제에 대한 답은 다음과 같습니다.

Firebase를 구성하려면 FIRApp.configure()를 어딘가에서 실행해야 합니다.이 작업이 완료되면 let firebaseDatabaseReference = FIRDabase.database().reference()사용하여 해당 데이터베이스에 대한 참조를 가져와 사용을 시작할 수 있습니다.문제는 Firebase "그 자체"가 아니라 Swift의 행동 방식에 있습니다.

만약 당신이FIRApp.configure()앱 대리인에서func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool그리고 나서.MyDatabase class당신이 사용하는let firebaseDatabaseReference = FIRDatabase.database().reference() 선언기능을 벗어나면 때때로 코드가FIRDatabase.database().reference()앞에서 실행됩니다.application didFinishLaunchingWithOptions함수가 실행됩니다.

기본적으로 클래스가 Firebase 데이터베이스를 구성하기 전에 Firebase 데이터베이스에 대한 참조를 가져오려고 합니다. 콘솔에 "기본 앱이 아직 구성되지 않았습니다."라는 오류가 발생합니다.

참고: 이는 항상 발생하는 것은 아닙니다. 예를 들어 iOS Simulator에서 애플리케이션 시작이 느릴 때가 있으며 MyDatabase "let"이 실행되어 참조를 얻기 전에 완료할 기회가 없습니다.

그렇기 때문에 FIRAp.configure() 코드를 AppDelegate에서 init()를 재정의하도록 이동하면 작동하며, 기본적으로 AppDelegate가 초기화될 때(대부분의 경우 MyDatabase가 초기화되기 전) 구성 코드가 실행되도록 합니다.

override init() {
   super.init()
   FIRApp.configure()
   // not really needed unless you really need it FIRDatabase.database().persistenceEnabled = true
}

또한 super.init()(super 클래스가 "메시지"를 받도록)를 확인하여 오버라이드가 득보다 실이 더 많지 않도록 하십시오.

저도 사용하고 있습니다.Fabric그리고 내 경우에는 그것이 순서였습니다.Fabric그리고.Firebase초기화초기화해야 했습니다.Firebase첫번째.

그래서 변화하는 것

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Fabric.with([Crashlytics.self])
    FirebaseApp.configure()
    ...
}

대상:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    Fabric.with([Crashlytics.self])
    ...
}

문제를 해결했습니다.

AppDelegate.m이외에didFinishLaunchingWithOptions,

override init() {
   FIRApp.configure()
   FIRDatabase.database().persistenceEnabled = true
}

당신이 그것을 가지고 있는지 확인하세요.DATABASE_URL키 입력GoogleService-Info.plist

Swift 5 - 간편한 솔루션

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

return true
}


//MARK:- This function will auto run and firebase will configure successfully
override init() {
    super.init()
        FirebaseApp.configure()
        // not really needed unless you really need it 
        FIRDatabase.database().persistenceEnabled = true
}

해피 코딩

iOS 9.2
스위프트 2.1.1
Xcode 7.2.1
Mac OSX 10.10.5

다음 코드를 사용하는 경우에도 동일한 오류가 발생합니다.

AppDelegate.swift:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        FIRApp.configure()


        return true
    }

ViewController.swift:

import UIKit
import Firebase

class ViewController: UIViewController {


    var db = FIRDatabase.database().reference()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        //Create some data in Firebase db:
        db.child("key").child("subkey").setValue("hello world")

    }

저는 또한 파일을 추가했습니다.GoogleService-Info.plistFirebase 시작 안내서에 설명된 대로 프로젝트 디렉터리로 이동합니다.

그리고 다음 규칙을 사용하여 Firebase DB를 공개했습니다.

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

ViewController.swift를 다음과 같이 변경한 것이 제게 도움이 되었습니다.

class ViewController: UIViewController {


    var db: FIRDatabaseReference!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        db = FIRDatabase.database().reference()
        db.child("key").child("subkey").setValue("hello world")

    }

앱을 실행하기 전에 Firebase db는 다음과 같습니다.

myiosdata-abc123: null

앱을 실행한 후 Firebase db는 다음과 같습니다.

myiosdata-abc123
- key
   |
   +--- subkey: “hello world”

저는 몇 가지 정상적인 작업 프로젝트를 가지고 있었습니다.FIRApp.configure ()에 코드를 넣다.AppDelegate.swift:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        FIRApp.configure()
        return true
    }

꽤 오랫동안 모든 것이 잘 작동했지만, 어제와 오늘 저는 문을 열었습니다.Swift 3 내안프트젝 안에 Xcode 7.3.1(나는 여전히 일하고 있습니다.Swift 2 개봉했습니다.Swift 3무엇이 바뀌었는지 보기 위한 프로젝트), 그리고 갑자기 나의 모든 것에서.Swift 2가 아직한 오류가 했습니다.

기본 앱이 아직 구성되지 않았습니다.

모든 프로젝트를 XCode로 열었을 때 똑같은 오류가 발생하여 어떻게 해야 할지 몰랐지만, @Michael Williams의 코드를 구현한 후에는 모든 것이 다시 정상적으로 작동합니다.

Xcode(클리어 및 다시 로드 콘솔)를 디버그했지만, Michael의 이 새로운 접근 방식 외에는 아무 것도 작동하지 않습니다.

이것으로 문제가 해결되었습니다.

override init() {
   FIRApp.configure()
   FIRDatabase.database().persistenceEnabled = true
}

이 새로운 코드로 인해 앱이 불안정해지고 Firebase 데이터베이스에 연결/작동하는 데 문제가 발생하는 것을 두려워할 수 있습니까?

콘솔에서 GoogleService-Info.plist를 다시 다운로드하여 프로젝트에 추가해 보십시오. 저에게 효과가 있었습니다!

Xcode 9, Swift 4 및 Firebase 4를 사용하는 경우 다음을 수행하십시오.

override init() {
    FirebaseApp.configure()
    Database.database().isPersistenceEnabled = true
}

여기서 저에게 가장 깨끗한 해결책은 당신이 당신의 파일 위에 db를 올리고 싶을 때를 대비해 게으른 속성을 갖는 것입니다.예를 들어 Firebase 서비스 클래스가 있다고 가정해 보겠습니다.Firestore.firestore()해당 클래스의 모든 함수에 사용할 db 상수:

private lazy var db = Firestore.firestore()

또는 Firebase 스토리지를 사용하는 경우:

private lazy var storage = Storage.storage().reference()

에는 또데스이스/토리지경우에서 하십시오.init()당신의 수업 중, 당신은 여전히 같은 문제를 가지고 있을 수 있으니 그것을 피하세요.

언급URL : https://stackoverflow.com/questions/37334323/the-default-app-has-not-been-configured-yet

반응형