This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Update location_background #906
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
@implementation LocationBackgroundPlugin { | ||
CLLocationManager *_locationManager; | ||
FlutterHeadlessDartRunner *_headlessRunner; | ||
FlutterEngine *_headlessEngine; | ||
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, *)) { | ||
_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]; | ||
_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<FlutterPluginRegistrar> *)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]; | ||
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]; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@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 comment
The 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 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).