diff --git a/packages/location_background/ios/Classes/LocationBackgroundPlugin.m b/packages/location_background/ios/Classes/LocationBackgroundPlugin.m index ea266a91013e..2370d5ce6a87 100644 --- a/packages/location_background/ios/Classes/LocationBackgroundPlugin.m +++ b/packages/location_background/ios/Classes/LocationBackgroundPlugin.m @@ -8,7 +8,7 @@ @implementation LocationBackgroundPlugin { CLLocationManager *_locationManager; - FlutterHeadlessDartRunner *_headlessRunner; + FlutterEngine *_headlessEngine; FlutterMethodChannel *_callbackChannel; FlutterMethodChannel *_mainChannel; NSObject *_registrar; @@ -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]; } @@ -97,7 +99,8 @@ - (instancetype)init:(NSObject *)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. @@ -113,7 +116,7 @@ - (instancetype)init:(NSObject *)registrar { // `startHeadlessService` below. _callbackChannel = [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/ios_background_location_callback" - binaryMessenger:_headlessRunner]; + binaryMessenger:_headlessEngine]; return self; } @@ -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 @@ -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]; }