I am struggling to get a local notification to run using background fetch. Ideally what I need is to update my JSON data and if it contains a value then send a local notification to the user.

as yet I am unable to even send a local notification using background fetch.

I have checked out the following: Send Local Notifications while App is running in the background Swift 2.0

ios call function in background mode

and a tutorial https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started

I am still unable to send even a notification let alone do my json query in the background to check for a value.

here is my code for appdelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum) return true } func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { if let vc = window?.rootViewController as? FirstViewController { vc.mynotifications() } }

and my notification code from the view controller:

func mynotifications() { let content = UNMutableNotificationContent() content.title = "title" content.subtitle = "subtitle" content.body = "test" content.badge = 1 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.5, repeats: false) let request = UNNotificationRequest(identifier: "timerdone", content: content, trigger: trigger) UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) }

I have background fetch enabled in my settings.

Any assistance in getting this to work would be appreciated. If you could also point me in the right direction to tie in the json request in the background that would also be a bonus.

Thanks