Asked this on forum.qt.io, but with no help...can someone here offer any insight?
=========================================
When running my app on iOS 9 that collects the user's location (typically once per second) and the app is backgrounded, the OS kills the geolocation service. I have updated the info.plist to account for required background modes and the location services according to the Apple docs. But, processing still stops.
On iOS 6.1, however, this does not happen, processing continues when the app is backgrounded.
According to StackOverflow, we should be using this to enable background locations in iOS 9...but how do we do that with Qt?
Qt Code:
if ([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates:)]) { self.locationManager.allowsBackgroundLocationUpdates = YES; }To copy to clipboard, switch view to plain text mode
http://stackoverflow.com/questions/3...-in-background
SO, I am doing the following, which works in the iOS simulator (iOS 9, iPhone6), but not on the phone.
I call EnableIOSBackgroundLocation() in my main.cpp file. The return Boolean sets a QML Image to be visible (either a green GPS icon on success or a red one on failure).
In the simulator, the green GPS icon shows up...and the location continues to be logged when the app is put in the background. On a real iPhone running iOS 9, the green GPS icon shows up also, but the GPS is killed after a couple of minutes when the app is backgrounded.
Anyone have any ideas why?
iosLocation .mm:
Qt Code:
#include "ioslocation.h" #import <CoreLocation/CoreLocation.h> bool IOSLocation::EnableIOSBackgroundLocation() { CLLocationManager *locationManager; locationManager = [[CLLocationManager alloc] init]; if ([locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates:)]) { locationManager.allowsBackgroundLocationUpdates = YES; if ([locationManager respondsToSelector:@selector(pausesLocationUpdatesAutomatically:)]) { locationManager.pausesLocationUpdatesAutomatically = NO; // Request location authorization [locationManager requestAlwaysAuthorization]; // Set an accuracy level. The higher, the better for energy. locationManager.desiredAccuracy = kCLLocationAccuracyBest; // Specify the type of activity your app is currently performing locationManager.activityType = CLActivityTypeOtherNavigation; // Set distance filter to NONE locationManager.distanceFilter = kCLDistanceFilterNone; return true; } else { return false; } } return false; }To copy to clipboard, switch view to plain text mode
iosLocation .h:
Qt Code:
#ifndef _iosLocation_h #define _iosLocation_h class IOSLocation { public: static void EnableIOSBackgroundLocation(); }; #endifTo copy to clipboard, switch view to plain text mode
Anyone have any ideas on why this is happening? Ideas on how to get around it and make it work?
--Sam
Bookmarks