How to receive Darwin notifications when the app is in the background

The application is configured to receive location updates in the background to keep the application active and receive updates when the application is in the background.

Darwin notifications have also been configured and are only accepted when the application is the current application in the foreground. Once the application is placed in the background image, it will stop receiving Darwin notifications.

Any thoughts on how to get Darwin notifications when the app is in the background?

The following are snippets of code.

Creating an Application 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() 
+5
source share
1 answer

Make sure you activate Location updates in Background Modes .

Ability to update location

This will allow your application to receive location changes in the background and execute its logic. A great library for this kind of INTULocationManager functions.

0
source

Source: https://habr.com/ru/post/1247567/


All Articles