title: Can I make network calls within my iOS background fetch?
body: <p>I am currently trying to create notifications when a user has new messages. I'm trying to do this with local notifications because I'm very much a beginner and it seems(?) easier than push notifications. My question is, can I check my Firebase database during my background fetch?</p>
  
  <p>What I've experienced is that the background fetch function works- but only before my app memory has been suspended, thus negating the point of the background fetch. I run it, I simulate a background fetch, but unless the app was just open, it does nothing and tells me "<code>Warning: Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called.</code>"</p>
  
  <p>Here's my code if it's useful. I know it probably seems like a funky way to go about this.</p>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
  
          //Firebase
          FirebaseApp.configure()
  
          //there was other firebase stuff here that I don't think is relevant to this question
  
          UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (didAllow, error) in
  
          }
  
          UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
  
          return true
      }
  
      func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
  
          myDatabase.child("users").child(userID!).child("hasNewMessages").observeSingleEvent(of: .value) { (snapshot) in
              if snapshot.value as! Bool == true {
                  let content = UNMutableNotificationContent()
                  content.title = "You have unread messages"
                  content.badge = 1
  
                  let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
                  let request = UNNotificationRequest(identifier: "testing", content: content, trigger: trigger)
  
                  UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
              }
          }
      }
  </code></pre>