From 6ab36c886885cd3acc5675fe8656f03081966c07 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Wed, 30 Nov 2022 20:15:54 +0200 Subject: [PATCH 01/14] fix example --- example/android/app/build.gradle | 4 +- example/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/lib/main.dart | 104 +++++++++--------- example/pubspec.yaml | 1 + 5 files changed, 60 insertions(+), 55 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 74edea83..4cb687af 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 33 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -40,7 +40,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "io.flutter.plugins.geofencing_example" minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/example/android/build.gradle b/example/android/build.gradle index 13546311..b3afb285 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.5.10' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.1' + classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index f0287495..78240b49 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/example/lib/main.dart b/example/lib/main.dart index 3df1489e..ecf3c9f0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -9,6 +9,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:geofencing/geofencing.dart'; +import 'package:permission_handler/permission_handler.dart'; void main() => runApp(MyApp()); @@ -20,28 +21,30 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { String geofenceState = 'N/A'; List registeredGeofences = []; - double latitude = 37.419851; - double longitude = -122.078818; - double radius = 150.0; + double latitude = 49.98414; + double longitude = 36.26894; + double radius = 200.0; ReceivePort port = ReceivePort(); final List triggers = [ GeofenceEvent.enter, - GeofenceEvent.dwell, GeofenceEvent.exit ]; final AndroidGeofencingSettings androidSettings = AndroidGeofencingSettings( - initialTrigger: [ - GeofenceEvent.enter, - GeofenceEvent.exit, - GeofenceEvent.dwell - ], - loiteringDelay: 1000 * 60); + initialTrigger: [ + GeofenceEvent.enter, + GeofenceEvent.exit, + ], + loiteringDelay: 0, + notificationResponsiveness: 0, + ); @override void initState() { super.initState(); IsolateNameServer.registerPortWithName( - port.sendPort, 'geofencing_send_port'); + port.sendPort, + 'geofencing_send_port', + ); port.listen((dynamic data) { print('Event: $data'); setState(() { @@ -51,14 +54,43 @@ class _MyAppState extends State { initPlatformState(); } + void registerGeofence() async { + final firstPermission = await Permission.locationWhenInUse.request(); + final secondPermission = await Permission.locationAlways.request(); + if (firstPermission.isGranted && secondPermission.isGranted) { + await GeofencingManager.registerGeofence( + GeofenceRegion( + 'mtv', + latitude, + longitude, + radius, + triggers, + androidSettings: androidSettings, + ), + callback, + ); + final registeredIds = await GeofencingManager.getRegisteredGeofenceIds(); + setState(() { + registeredGeofences = registeredIds; + }); + } + } + + void unregisteGeofence() async { + await GeofencingManager.removeGeofenceById('mtv'); + final registeredIds = await GeofencingManager.getRegisteredGeofenceIds(); + setState(() { + registeredGeofences = registeredIds; + }); + } + static void callback(List ids, Location l, GeofenceEvent e) async { print('Fences: $ids Location $l Event: $e'); final SendPort send = - IsolateNameServer.lookupPortByName('geofencing_send_port'); + IsolateNameServer.lookupPortByName('geofencing_send_port'); send?.send(e.toString()); } - // Platform messages are asynchronous, so we initialize in an async method. Future initPlatformState() async { print('Initializing...'); await GeofencingManager.initialize(); @@ -90,44 +122,16 @@ class _MyAppState extends State { children: [ Text('Current state: $geofenceState'), Center( - child: RaisedButton( + child: TextButton( child: const Text('Register'), - onPressed: () { - if (latitude == null) { - setState(() => latitude = 0.0); - } - if (longitude == null) { - setState(() => longitude = 0.0); - } - if (radius == null) { - setState(() => radius = 0.0); - } - GeofencingManager.registerGeofence( - GeofenceRegion( - 'mtv', latitude, longitude, radius, triggers, - androidSettings: androidSettings), - callback).then((_) { - GeofencingManager.getRegisteredGeofenceIds().then((value) { - setState(() { - registeredGeofences = value; - }); - }); - }); - }, + onPressed: registerGeofence, ), ), Text('Registered Geofences: $registeredGeofences'), Center( - child: RaisedButton( + child: TextButton( child: const Text('Unregister'), - onPressed: () => - GeofencingManager.removeGeofenceById('mtv').then((_) { - GeofencingManager.getRegisteredGeofenceIds().then((value){ - setState(() { - registeredGeofences = value; - }); - }); - }), + onPressed: unregisteGeofence, ), ), TextField( @@ -136,17 +140,17 @@ class _MyAppState extends State { ), keyboardType: TextInputType.number, controller: - TextEditingController(text: latitude.toString()), + TextEditingController(text: latitude.toString()), onChanged: (String s) { latitude = double.tryParse(s); }, ), TextField( decoration: - const InputDecoration(hintText: 'Longitude'), + const InputDecoration(hintText: 'Longitude'), keyboardType: TextInputType.number, controller: - TextEditingController(text: longitude.toString()), + TextEditingController(text: longitude.toString()), onChanged: (String s) { longitude = double.tryParse(s); }), @@ -154,11 +158,11 @@ class _MyAppState extends State { decoration: const InputDecoration(hintText: 'Radius'), keyboardType: TextInputType.number, controller: - TextEditingController(text: radius.toString()), + TextEditingController(text: radius.toString()), onChanged: (String s) { radius = double.tryParse(s); }), ]))), ); } -} \ No newline at end of file +} diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f0512163..f41adf44 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 + permission_handler: ^10.2.0 dev_dependencies: flutter_test: From 040294282d96f2e6c02397de5fb64b2bbaa10a0e Mon Sep 17 00:00:00 2001 From: vovaklh Date: Wed, 30 Nov 2022 20:24:18 +0200 Subject: [PATCH 02/14] fix in release mode --- lib/src/callback_dispatcher.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index fe1e0bad..9f1b93b5 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -10,6 +10,7 @@ import 'package:flutter/services.dart'; import 'package:geofencing/src/geofencing.dart'; import 'package:geofencing/src/location.dart'; +@pragma('vm:entry-point') void callbackDispatcher() { const MethodChannel _backgroundChannel = MethodChannel('plugins.flutter.io/geofencing_plugin_background'); From 716de6613d23d764f7bbfc0ae150c73648b1ab33 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Wed, 30 Nov 2022 20:34:09 +0200 Subject: [PATCH 03/14] remove pragma --- lib/src/callback_dispatcher.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index 9f1b93b5..fe1e0bad 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -10,7 +10,6 @@ import 'package:flutter/services.dart'; import 'package:geofencing/src/geofencing.dart'; import 'package:geofencing/src/location.dart'; -@pragma('vm:entry-point') void callbackDispatcher() { const MethodChannel _backgroundChannel = MethodChannel('plugins.flutter.io/geofencing_plugin_background'); From 1e88902c8001bdc9c4766ee80d356bed63e2759d Mon Sep 17 00:00:00 2001 From: vovaklh Date: Thu, 1 Dec 2022 14:53:19 +0200 Subject: [PATCH 04/14] migrate to nullsafety --- example/lib/main.dart | 2 +- lib/src/callback_dispatcher.dart | 4 ++-- lib/src/geofencing.dart | 21 +++++++++++++-------- pubspec.yaml | 5 ++--- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index ecf3c9f0..565872ef 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -65,7 +65,7 @@ class _MyAppState extends State { longitude, radius, triggers, - androidSettings: androidSettings, + androidSettings, ), callback, ); diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index fe1e0bad..5186575d 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -17,7 +17,7 @@ void callbackDispatcher() { _backgroundChannel.setMethodCallHandler((MethodCall call) async { final List args = call.arguments; - final Function callback = PluginUtilities.getCallbackFromHandle( + final Function? callback = PluginUtilities.getCallbackFromHandle( CallbackHandle.fromRawHandle(args[0])); assert(callback != null); final List triggeringGeofences = args[1].cast(); @@ -29,7 +29,7 @@ void callbackDispatcher() { .forEach((dynamic e) => locationList.add(double.parse(e.toString()))); final Location triggeringLocation = locationFromList(locationList); final GeofenceEvent event = intToGeofenceEvent(args[3]); - callback(triggeringGeofences, triggeringLocation, event); + callback?.call(triggeringGeofences, triggeringLocation, event); }); _backgroundChannel.invokeMethod('GeofencingService.initialized'); } diff --git a/lib/src/geofencing.dart b/lib/src/geofencing.dart index be09b06b..844a6425 100644 --- a/lib/src/geofencing.dart +++ b/lib/src/geofencing.dart @@ -72,10 +72,13 @@ class GeofenceRegion { final AndroidGeofencingSettings androidSettings; GeofenceRegion( - this.id, double latitude, double longitude, this.radius, this.triggers, - {AndroidGeofencingSettings androidSettings}) - : location = Location(latitude, longitude), - androidSettings = (androidSettings ?? AndroidGeofencingSettings()); + this.id, + double latitude, + double longitude, + this.radius, + this.triggers, + this.androidSettings, + ) : location = Location(latitude, longitude); List _toArgs() { final int triggerMask = triggers.fold( @@ -102,10 +105,12 @@ class GeofencingManager { /// Initialize the plugin and request relevant permissions from the user. static Future initialize() async { - final CallbackHandle callback = + final CallbackHandle? callback = PluginUtilities.getCallbackHandle(callbackDispatcher); - await _channel.invokeMethod('GeofencingPlugin.initializeService', - [callback.toRawHandle()]); + if (callback != null) { + await _channel.invokeMethod('GeofencingPlugin.initializeService', + [callback.toRawHandle()]); + } } /// Promote the geofencing service to a foreground service. @@ -142,7 +147,7 @@ class GeofencingManager { throw UnsupportedError("iOS does not support 'GeofenceEvent.dwell'"); } final List args = [ - PluginUtilities.getCallbackHandle(callback).toRawHandle() + PluginUtilities.getCallbackHandle(callback)!.toRawHandle() ]; args.addAll(region._toArgs()); await _channel.invokeMethod('GeofencingPlugin.registerGeofence', args); diff --git a/pubspec.yaml b/pubspec.yaml index e4fa136d..b3a5ad08 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,11 @@ name: geofencing description: A geofencing plugin for Flutter applications. version: 0.1.0 -author: Ben Konyi homepage: https://github.com/flutter/plugins environment: - sdk: ">=2.1.0 <3.0.0" - flutter: "^1.12.0" + sdk: ">=2.12.0 <3.0.0" + flutter: "^2.0.0" dependencies: flutter: From 22243708465459491d69eeae75e76d4b47451979 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Fri, 2 Dec 2022 10:59:09 +0200 Subject: [PATCH 05/14] add pragma entrypoint --- lib/src/callback_dispatcher.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index 5186575d..12d88798 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -10,6 +10,7 @@ import 'package:flutter/services.dart'; import 'package:geofencing/src/geofencing.dart'; import 'package:geofencing/src/location.dart'; +@pragma('vm:entry-point') void callbackDispatcher() { const MethodChannel _backgroundChannel = MethodChannel('plugins.flutter.io/geofencing_plugin_background'); From 36d0d66972e259a3c63b4fd195c9fbd06c7651ab Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 3 Dec 2022 12:36:46 +0200 Subject: [PATCH 06/14] update android dependencies --- android/build.gradle | 4 ++-- android/gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index aa5dced1..2438660d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,7 @@ group 'io.flutter.plugins.geofencing' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.5.30' + ext.kotlin_version = '1.6.10' repositories { google() @@ -10,7 +10,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 4c83d2a1..cb24abda 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip From e33716be51e26b1cc4effd3180fafa12a93afa4f Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 3 Dec 2022 12:44:59 +0200 Subject: [PATCH 07/14] fix example --- example/android/build.gradle | 4 ++-- example/android/gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index b3afb285..31e95773 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.5.10' + ext.kotlin_version = '1.6.10' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 78240b49..31b394db 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip From d67baea97ef2404c5c066de18624e6b765f405ad Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 3 Dec 2022 13:07:55 +0200 Subject: [PATCH 08/14] remove permissions for IOS on start --- ios/Classes/GeofencingPlugin.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Classes/GeofencingPlugin.m b/ios/Classes/GeofencingPlugin.m index 130dd739..6772de6d 100644 --- a/ios/Classes/GeofencingPlugin.m +++ b/ios/Classes/GeofencingPlugin.m @@ -143,8 +143,8 @@ - (instancetype)init:(NSObject *)registrar { _eventQueue = [[NSMutableArray alloc] init]; _locationManager = [[CLLocationManager alloc] init]; [_locationManager setDelegate:self]; - [_locationManager requestAlwaysAuthorization]; - _locationManager.allowsBackgroundLocationUpdates = YES; + // [_locationManager requestAlwaysAuthorization]; + // _locationManager.allowsBackgroundLocationUpdates = YES; _headlessRunner = [[FlutterEngine alloc] initWithName:@"GeofencingIsolate" project:nil allowHeadlessExecution:YES]; _registrar = registrar; From a5bb45b0b6144284d52d054a43954a14f9600b20 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 3 Dec 2022 13:12:40 +0200 Subject: [PATCH 09/14] revert permissions --- ios/Classes/GeofencingPlugin.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Classes/GeofencingPlugin.m b/ios/Classes/GeofencingPlugin.m index 6772de6d..130dd739 100644 --- a/ios/Classes/GeofencingPlugin.m +++ b/ios/Classes/GeofencingPlugin.m @@ -143,8 +143,8 @@ - (instancetype)init:(NSObject *)registrar { _eventQueue = [[NSMutableArray alloc] init]; _locationManager = [[CLLocationManager alloc] init]; [_locationManager setDelegate:self]; - // [_locationManager requestAlwaysAuthorization]; - // _locationManager.allowsBackgroundLocationUpdates = YES; + [_locationManager requestAlwaysAuthorization]; + _locationManager.allowsBackgroundLocationUpdates = YES; _headlessRunner = [[FlutterEngine alloc] initWithName:@"GeofencingIsolate" project:nil allowHeadlessExecution:YES]; _registrar = registrar; From 36ff895408f317a87551a7611d2b5c4a35a53618 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 3 Dec 2022 16:43:04 +0200 Subject: [PATCH 10/14] change java sdk --- android/build.gradle | 2 +- example/android/app/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 2438660d..e70331fd 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,6 +41,6 @@ android { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "com.google.android.gms:play-services-location:17.+" } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 4cb687af..2cbea396 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -60,7 +60,7 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' From 37428a18b4338a6b43fb2fa328849f630eb171b7 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sun, 4 Dec 2022 12:41:17 +0200 Subject: [PATCH 11/14] fix release --- example/android/app/src/main/AndroidManifest.xml | 3 ++- example/lib/main.dart | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 3425186e..9e4d3863 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -15,6 +15,7 @@ + android:enabled="true" android:exported="true"> diff --git a/example/lib/main.dart b/example/lib/main.dart index 565872ef..1e831a66 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -21,8 +21,8 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { String geofenceState = 'N/A'; List registeredGeofences = []; - double latitude = 49.98414; - double longitude = 36.26894; + double latitude = 50.00187; + double longitude = 36.23866; double radius = 200.0; ReceivePort port = ReceivePort(); final List triggers = [ @@ -84,6 +84,7 @@ class _MyAppState extends State { }); } + @pragma('vm:entry-point') static void callback(List ids, Location l, GeofenceEvent e) async { print('Fences: $ids Location $l Event: $e'); final SendPort send = From 192be9e2cf8595d14f30573a2b5840d53b7aad8a Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sun, 4 Dec 2022 14:36:21 +0200 Subject: [PATCH 12/14] try remove permissions on IOS --- ios/Classes/GeofencingPlugin.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Classes/GeofencingPlugin.m b/ios/Classes/GeofencingPlugin.m index 130dd739..6772de6d 100644 --- a/ios/Classes/GeofencingPlugin.m +++ b/ios/Classes/GeofencingPlugin.m @@ -143,8 +143,8 @@ - (instancetype)init:(NSObject *)registrar { _eventQueue = [[NSMutableArray alloc] init]; _locationManager = [[CLLocationManager alloc] init]; [_locationManager setDelegate:self]; - [_locationManager requestAlwaysAuthorization]; - _locationManager.allowsBackgroundLocationUpdates = YES; + // [_locationManager requestAlwaysAuthorization]; + // _locationManager.allowsBackgroundLocationUpdates = YES; _headlessRunner = [[FlutterEngine alloc] initWithName:@"GeofencingIsolate" project:nil allowHeadlessExecution:YES]; _registrar = registrar; From 7c4b7bd9ab20cba505f61f53c39a24be8327a62c Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 10 Dec 2022 09:26:14 +0200 Subject: [PATCH 13/14] remove permissions from Android --- .../kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt index 299b3155..b84f96ba 100644 --- a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt +++ b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt @@ -257,11 +257,6 @@ class GeofencingPlugin : ActivityAware, FlutterPlugin, MethodCallHandler { val args = call.arguments>() when(call.method) { "GeofencingPlugin.initializeService" -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - mActivity?.requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION), 12312) - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - mActivity?.requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 12312) - } initializeService(mContext!!, args) result.success(true) } From 47f2bc3dc4502b220919bfb93542f11466316ff3 Mon Sep 17 00:00:00 2001 From: vovaklh Date: Sat, 10 Dec 2022 10:20:40 +0200 Subject: [PATCH 14/14] update documentation --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 708a01ee..3f1c662e 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ geofencing: Also request the correct permissions for geofencing: ```xml + ``` @@ -42,7 +43,6 @@ class Application : FlutterApplication(), PluginRegistrantCallback { } override fun registerWith(registry: PluginRegistry) { - GeneratedPluginRegistrant.registerWith(registry); } } ``` @@ -59,7 +59,6 @@ public class Application extends FlutterApplication implements PluginRegistrantC @Override public void registerWith(PluginRegistry registry) { - GeneratedPluginRegistrant.registerWith(registry); } } ``` @@ -105,6 +104,36 @@ And request the correct permissions for geofencing: ``` +Add this line to `Runner-Briding-Header.h` + +```h +#import +``` + +At the end add this line to `AppDelegate.swift` + +```swift +GeofencingPlugin.setPluginRegistrantCallback { (registry) in GeneratedPluginRegistrant.register(with: registry) } +``` + +### Notes +Before register geofence request permissions for location and location always. You can use *permission_handler* package. Don't forget include this line in `Podfile` + +```ruby +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + target.build_configurations.each do |config| + config.build_settings['ENABLE_BITCODE'] = 'NO' + config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ + '$(inherited)', + 'PERMISSION_LOCATION=1', + ] + end + end +end +``` + ### Need Help? For help getting started with Flutter, view our online