-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Update location_background #906
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
@implementation LocationBackgroundPlugin { | ||
CLLocationManager *_locationManager; | ||
FlutterHeadlessDartRunner *_headlessRunner; | ||
FlutterEngine *_headlessRunner; | ||
FlutterMethodChannel *_callbackChannel; | ||
FlutterMethodChannel *_mainChannel; | ||
NSObject<FlutterPluginRegistrar> *_registrar; | ||
|
@@ -48,7 +48,9 @@ - (BOOL)application:(UIApplication *)application | |
_locationManager.showsBackgroundLocationIndicator = | ||
[self getShowsBackgroundLocationIndicator]; | ||
} | ||
_locationManager.allowsBackgroundLocationUpdates = YES; | ||
if (@available(iOS 9.0, *)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error or warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
} | ||
|
@@ -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. | ||
|
@@ -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 | ||
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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