5

App is configured to receive location updates while in the background so as to keep the app active and the updates are being received successfully when app is in the background.

Darwin notifications have also been configured and are received only when the app is the current app in the foreground. As soon as the app is put in the background it stops receiving the Darwin Notifications.

Any thoughts on how to receive the Darwin Notifications while the app is in the background?

Code snippets below.

Building App in Swift2

in appdeligate

    let callback: @convention(c)
    (CFNotificationCenter!, UnsafeMutablePointer<Void>, CFString!, UnsafePointer<Void>,        CFDictionary!) -> Void = {
        (center, observer, name, object, userInfo) in

    //Execute callback code

    }


    let exCb: CFNotificationCallback = unsafeBitCast(callback, CFNotificationCallback.self)

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),nil ,exCb,"com.apple.springboard.hasBlankedScreen" as CFString,nil ,CFNotificationSuspensionBehavior.DeliverImmediately)

in viewcontroller

    locationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    //locationManager.requestWhenInUseAuthorization()
    locationManager.requestAlwaysAuthorization()
    locationManager.startUpdatingLocation()
Rich16
  • 87
  • 7

1 Answers1

0

Make sure you've activated the Location updates capability in Background Modes.

Location updates capability

This will allow your app to receive location changes in the background and proceed with your logic. A great library for this kind of functionality is INTULocationManager.

Alexis C.
  • 4,898
  • 1
  • 31
  • 43