Skip to content

Commit

Permalink
Update location_background (flutter#906)
Browse files Browse the repository at this point in the history
* Update location_background
  • Loading branch information
dnfield authored Nov 19, 2018
1 parent 535124f commit 78e23e4
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@implementation LocationBackgroundPlugin {
CLLocationManager *_locationManager;
FlutterHeadlessDartRunner *_headlessRunner;
FlutterEngine *_headlessEngine;
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, *)) {
_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];
_headlessEngine =
[[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 All @@ -113,7 +116,7 @@ - (instancetype)init:(NSObject<FlutterPluginRegistrar> *)registrar {
// `startHeadlessService` below.
_callbackChannel = [FlutterMethodChannel
methodChannelWithName:@"plugins.flutter.io/ios_background_location_callback"
binaryMessenger:_headlessRunner];
binaryMessenger:_headlessEngine];
return self;
}

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];
[_headlessEngine 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];
}
_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

0 comments on commit 78e23e4

Please sign in to comment.