1

I'm trying to get a background fetch up and running in an iPhone app.

I'd like the app to notify the user with a notification that a new item has been fetched from a server.

And added the following code in appDelegate & I have the background mode checked in Capabilities:

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

    UIApplication.shared.setMinimumBackgroundFetchInterval(30)
  .
  .

}

 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> ())
{
    debugPrint("**** Fetch complete")
}

When I minimise the app how can I get it to send a notification to the user that a new item is available? What am I missing above?

Thanks

rubyist
  • 389
  • 4
  • 22
  • There is a pretty good [tutorial](https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started) of _Background Modes in iOS_. You can look at the ___Background Fetch___ option for your case. – nayem Jun 21 '17 at 18:53
  • Thanks for that, I got that to work, kind of, I can get my app to execute a fetch request once, however, I can't get it to fetch some data every hour for example. – rubyist Jun 25 '17 at 19:40

1 Answers1

0

I'm assuming that your server sends a remote notification to the device and then the device does what it has to such that an item becomes available. In that case, all you need to do is schedule a local notification to fire immediately and that will show the user a notification respectively.

TNguyen
  • 1,041
  • 9
  • 24