Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!