Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Enabling offline for firebase realtime database using Ionic app with capacitor

I am using ionic with firebase realtime database and capacitor 3. I intend to enable offline capabilities. I have built the app using ionic cap build and then opened in xcode. Then following url https://firebase.google.com/docs/database/ios/offline-capabilities I added the below code in AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        Database.database().isPersistenceEnabled = true

        return true
    }

Now to test i ran the app with wifi on and got the data from firebase db. after this i killed the app and turned off wifi. However, on launching the app it does not load the data.

Is there anything else i am missing here?

my key pod file has:

target 'App' do
  capacitor_pods
  # Add your Pods here
  pod 'FirebaseCore', '7.11.0' # Add this line
  pod 'Firebase/Database', '7.11.0' # Add this line
end

Below is my code that does not work and expected to:

getSeedConfig(){
  return new Promise((resolve, reject) =>{
        const doc = ref(this.db, 'config/seed');
        get(doc).then((snapshot) => {
          if (snapshot.exists()) {
            resolve(snapshot.val())
          } else {
            resolve(null)
          }
        }).catch((error) => {
          reject(error)
        });
  })
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When using a modern API in JavaScript there are not many cases where you need to return a custom promise anymore.

As far as I can tell this code that you now have:

getSeedConfig(){
  return new Promise((resolve, reject) =>{
        const doc = ref(this.db, 'config/seed');
        get(doc).then((snapshot) => {
          if (snapshot.exists()) {
            resolve(snapshot.val())
          } else {
            resolve(null)
          }
        }).catch((error) => {
          reject(error)
        });
  })
}

Can be shortened to:

getSeedConfig(){
  const doc = ref(this.db, 'config/seed');
  return get(doc).then((snapshot) => {
    return snapshot.val(); // 👈 returns null when the snapshot does not exist
  })
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda