Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Update location_background #906

Merged
merged 3 commits into from
Nov 19, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@implementation LocationBackgroundPlugin {
CLLocationManager *_locationManager;
FlutterHeadlessDartRunner *_headlessRunner;
FlutterEngine *_headlessRunner;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we rename the variable as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, I didn't have strong opinions on it. It is still meant to be headless, never getting a Viewcontroller attached to it at present AFAIK

FlutterMethodChannel *_callbackChannel;
FlutterMethodChannel *_mainChannel;
NSObject<FlutterPluginRegistrar> *_registrar;
Expand Down Expand Up @@ -48,7 +48,9 @@ - (BOOL)application:(UIApplication *)application
_locationManager.showsBackgroundLocationIndicator =
[self getShowsBackgroundLocationIndicator];
}
_locationManager.allowsBackgroundLocationUpdates = YES;
if (@available(iOS 9.0, *)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkonyi What should we do when this is not supported? throw an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error or warning?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this isn't supported that parameter is ignored (pretty sure it's mentioned in the Dart docs).

_locationManager.allowsBackgroundLocationUpdates = YES;
}
// Finally, restart monitoring for location changes to get our location.
[self->_locationManager startMonitoringSignificantLocationChanges];
}
Expand Down Expand Up @@ -97,7 +99,8 @@ - (instancetype)init:(NSObject<FlutterPluginRegistrar> *)registrar {
[_locationManager setDelegate:self];
[_locationManager requestAlwaysAuthorization];

_headlessRunner = [[FlutterHeadlessDartRunner alloc] init];
_headlessRunner = [[FlutterEngine alloc] initWithName:@"io.flutter.plugins.location_background"
project:nil];
_registrar = registrar;

// This is the method channel used to communicate with the UI Isolate.
Expand Down Expand Up @@ -178,7 +181,7 @@ - (void)startHeadlessService:(int64_t)handle {

// Here we actually launch the background isolate to start executing our
// callback dispatcher, `_backgroundCallbackDispatcher`, in Dart.
[_headlessRunner runWithEntrypointAndLibraryUri:entrypoint libraryUri:uri];
[_headlessRunner runWithEntrypoint:entrypoint libraryURI:uri];

// The headless runner needs to be initialized before we can register it as a
// MethodCallDelegate or else we get an illegal memory access. If we don't
Expand All @@ -194,12 +197,14 @@ - (void)monitorLocationChanges:(NSArray *)arguments {
_locationManager.pausesLocationUpdatesAutomatically = arguments[1];
if (@available(iOS 11.0, *)) {
_locationManager.showsBackgroundLocationIndicator = arguments[2];
[self setShowsBackgroundLocationIndicator:_locationManager.showsBackgroundLocationIndicator];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkonyi - is it safe to move this up here? It seemed like it, but wanted to make sure there weren't expectations of setting any other state before calling this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should be fine. It's just saving the state to reset the location manager object, so ordering shouldn't really matter.

}
_locationManager.activityType = [arguments[3] integerValue];
_locationManager.allowsBackgroundLocationUpdates = YES;
if (@available(iOS 9.0, *)) {
_locationManager.allowsBackgroundLocationUpdates = YES;
}

[self setPausesLocationUpdatesAutomatically:_locationManager.pausesLocationUpdatesAutomatically];
[self setShowsBackgroundLocationIndicator:_locationManager.showsBackgroundLocationIndicator];
[self->_locationManager startMonitoringSignificantLocationChanges];
}

Expand Down