Hi Adam,
Thanks for your prompt reply.
Our client believe it’s strategic "when in use” permission only because competing applications are able to track activity without the need for too intrusive privacy like “always”. Our client fears that some users may delete the application after discovering that it only works when privacy is “always”.
After a day spent trying to figure out how to solve the problem digging in Expo Location library I found that there would be a quick and painless solution.These are settings for having what we want:
- When in use auth
- App registers for location updates in info.plist
- locationManager.allowsBackgroundLocationUpdates = YES;
- locationManager.showsBackgroundLocationIndicator = YES;
- [locationManager startUpdatingLocation];
https://developer.apple.com/documentation/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates
(Very long load page…)
- (void)startStandardUpdates
{
// Create the location manager if this object does not
// already have one.
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Set a movement threshold for new events.
locationManager.distanceFilter = 5; // meters
locationManager.allowsBackgroundLocationUpdates = YES;
locationManager.showsBackgroundLocationIndicator = YES;
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
}
Application will get location updates in background also with:
Location.watchPositionAsync
https://github.com/expo/expo/blob/master/packages/expo-location/ios/EXLocation/EXLocation.m
CLLocationManager *locMgr = [self locationManagerWithOptions:options];
- (CLLocationManager *)locationManagerWithOptions:(nullable NSDictionary *)options
{
CLLocationManager *locMgr = [[CLLocationManager alloc] init];
locMgr.allowsBackgroundLocationUpdates = NO;
if (options) {
locMgr.distanceFilter = options[@“distanceInterval”] ? [options[@“distanceInterval”] doubleValue] ?: kCLDistanceFilterNone : kCLLocationAccuracyHundredMeters;
if (options[@“accuracy”]) {
EXLocationAccuracy accuracy = [options[@“accuracy”] unsignedIntegerValue] ?: EXLocationAccuracyBalanced;
locMgr.desiredAccuracy = [self.class CLLocationAccuracyFromOption:accuracy];
}
}
return locMgr;
}
I think an easy solution could be add them by settings options:
if (options) {
locMgr.distanceFilter = options[@“distanceInterval”] ? [options[@“distanceInterval”] doubleValue] ?: kCLDistanceFilterNone : kCLLocationAccuracyHundredMeters;
locMgr.allowsBackgroundLocationUpdates = [options[@“allowsBackgroundLocationUpdates”] etc etc
locMgr.allowsBackgroundLocationIndicator = [options[@“allowsBackgroundLocationIndicator”] etc etc
if (options[@“accuracy”]) {
EXLocationAccuracy accuracy = [options[@“accuracy”] unsignedIntegerValue] ?: EXLocationAccuracyBalanced;
locMgr.desiredAccuracy = [self.class CLLocationAccuracyFromOption:accuracy];
}
}
Using this solution it would no longer be necessary to use Location.startLocationUpdatesAsync which requiring the creation of a TaskManager (which makes sense when using the GeoFence service) must necessarily request the “always” permission.
What do you think?
Many thanks.
Romeo
Romeo Mariani