Skip to content

Instantly share code, notes, and snippets.

@bkonyi
Last active February 19, 2019 20:31
- (instancetype)init:(NSObject<FlutterPluginRegistrar> *)registrar {
self = [super init];
NSAssert(self, @"super init cannot be nil");
// 1. Retrieve NSUserDefaults which will be used to store callback handles
// between launches.
_persistentState = [NSUserDefaults standardUserDefaults];
// 2. Initialize the location manager, and register as its delegate.
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
[_locationManager requestAlwaysAuthorization];
_locationManager.allowsBackgroundLocationUpdates = YES;
// 3. Initialize the Dart runner which will be used to run the callback
// dispatcher.
_headlessRunner = [[FlutterEngine alloc]
initWithName:@"GeofencingIsolate"
project:nil
allowHeadlessExecution:YES];
_registrar = registrar;
// 4. Create the method channel used by the Dart interface to invoke
// methods and register to listen for method calls.
_mainChannel = [FlutterMethodChannel
methodChannelWithName:@"plugins.flutter.io/geofencing_plugin"
binaryMessenger:[registrar messenger]];
[registrar addMethodCallDelegate:self channel:_mainChannel];
// 5. Create a second method channel to be used to communicate with the
// callback dispatcher. This channel will be registered to listen for
// method calls once the callback dispatcher is started.
_callbackChannel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/geofencing_plugin_background"
binaryMessenger:_headlessRunner];
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment