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

Commit 78e23e4

Browse files
authored
Update location_background (#906)
* Update location_background
1 parent 535124f commit 78e23e4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/location_background/ios/Classes/LocationBackgroundPlugin.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@implementation LocationBackgroundPlugin {
1010
CLLocationManager *_locationManager;
11-
FlutterHeadlessDartRunner *_headlessRunner;
11+
FlutterEngine *_headlessEngine;
1212
FlutterMethodChannel *_callbackChannel;
1313
FlutterMethodChannel *_mainChannel;
1414
NSObject<FlutterPluginRegistrar> *_registrar;
@@ -48,7 +48,9 @@ - (BOOL)application:(UIApplication *)application
4848
_locationManager.showsBackgroundLocationIndicator =
4949
[self getShowsBackgroundLocationIndicator];
5050
}
51-
_locationManager.allowsBackgroundLocationUpdates = YES;
51+
if (@available(iOS 9.0, *)) {
52+
_locationManager.allowsBackgroundLocationUpdates = YES;
53+
}
5254
// Finally, restart monitoring for location changes to get our location.
5355
[self->_locationManager startMonitoringSignificantLocationChanges];
5456
}
@@ -97,7 +99,8 @@ - (instancetype)init:(NSObject<FlutterPluginRegistrar> *)registrar {
9799
[_locationManager setDelegate:self];
98100
[_locationManager requestAlwaysAuthorization];
99101

100-
_headlessRunner = [[FlutterHeadlessDartRunner alloc] init];
102+
_headlessEngine =
103+
[[FlutterEngine alloc] initWithName:@"io.flutter.plugins.location_background" project:nil];
101104
_registrar = registrar;
102105

103106
// This is the method channel used to communicate with the UI Isolate.
@@ -113,7 +116,7 @@ - (instancetype)init:(NSObject<FlutterPluginRegistrar> *)registrar {
113116
// `startHeadlessService` below.
114117
_callbackChannel = [FlutterMethodChannel
115118
methodChannelWithName:@"plugins.flutter.io/ios_background_location_callback"
116-
binaryMessenger:_headlessRunner];
119+
binaryMessenger:_headlessEngine];
117120
return self;
118121
}
119122

@@ -178,7 +181,7 @@ - (void)startHeadlessService:(int64_t)handle {
178181

179182
// Here we actually launch the background isolate to start executing our
180183
// callback dispatcher, `_backgroundCallbackDispatcher`, in Dart.
181-
[_headlessRunner runWithEntrypointAndLibraryUri:entrypoint libraryUri:uri];
184+
[_headlessEngine runWithEntrypoint:entrypoint libraryURI:uri];
182185

183186
// The headless runner needs to be initialized before we can register it as a
184187
// MethodCallDelegate or else we get an illegal memory access. If we don't
@@ -194,12 +197,14 @@ - (void)monitorLocationChanges:(NSArray *)arguments {
194197
_locationManager.pausesLocationUpdatesAutomatically = arguments[1];
195198
if (@available(iOS 11.0, *)) {
196199
_locationManager.showsBackgroundLocationIndicator = arguments[2];
200+
[self setShowsBackgroundLocationIndicator:_locationManager.showsBackgroundLocationIndicator];
197201
}
198202
_locationManager.activityType = [arguments[3] integerValue];
199-
_locationManager.allowsBackgroundLocationUpdates = YES;
203+
if (@available(iOS 9.0, *)) {
204+
_locationManager.allowsBackgroundLocationUpdates = YES;
205+
}
200206

201207
[self setPausesLocationUpdatesAutomatically:_locationManager.pausesLocationUpdatesAutomatically];
202-
[self setShowsBackgroundLocationIndicator:_locationManager.showsBackgroundLocationIndicator];
203208
[self->_locationManager startMonitoringSignificantLocationChanges];
204209
}
205210

0 commit comments

Comments
 (0)