From 11c9b64440c3868b168c048c8cba44b1dc180829 Mon Sep 17 00:00:00 2001 From: DwayneCoussement Date: Thu, 15 Oct 2020 16:16:03 +0200 Subject: [PATCH] Android embedding v2 only (#31) * Android embedding v2 only * Cleanup --- .gitignore | 1 + .metadata | 10 + android/build.gradle | 3 +- android/gradle.properties | 1 - .../gradle/wrapper/gradle-wrapper.properties | 2 +- android/settings.gradle | 2 +- android/src/main/AndroidManifest.xml | 3 +- .../flutter_geofence/FlutterGeofencePlugin.kt | 194 +++++++++++++++++ .../GeofenceBroadcastReceiver.kt | 2 +- .../GeofenceManager.kt | 2 +- .../{geofence => flutter_geofence}/SafeLet.kt | 2 +- .../com/intivoto/geofence/GeofencePlugin.kt | 205 ------------------ .../flutter_geofence_example/MainActivity.kt | 6 + example/ios/Runner.xcodeproj/project.pbxproj | 6 +- example/pubspec.lock | 2 +- ios/Classes/FlutterGeofencePlugin.h | 4 + ...ofencePlugin.m => FlutterGeofencePlugin.m} | 6 +- ios/Classes/GeofencePlugin.h | 4 - ...swift => SwiftFlutterGeofencePlugin.swift} | 28 +-- pubspec.lock | 2 +- pubspec.yaml | 8 +- 21 files changed, 248 insertions(+), 245 deletions(-) create mode 100644 .metadata create mode 100644 android/src/main/kotlin/com/intivoto/flutter_geofence/FlutterGeofencePlugin.kt rename android/src/main/kotlin/com/intivoto/{geofence => flutter_geofence}/GeofenceBroadcastReceiver.kt (97%) rename android/src/main/kotlin/com/intivoto/{geofence => flutter_geofence}/GeofenceManager.kt (99%) rename android/src/main/kotlin/com/intivoto/{geofence => flutter_geofence}/SafeLet.kt (95%) delete mode 100644 android/src/main/kotlin/com/intivoto/geofence/GeofencePlugin.kt create mode 100644 example/android/app/src/main/kotlin/com/intivoto/flutter_geofence_example/MainActivity.kt create mode 100644 ios/Classes/FlutterGeofencePlugin.h rename ios/Classes/{GeofencePlugin.m => FlutterGeofencePlugin.m} (77%) delete mode 100644 ios/Classes/GeofencePlugin.h rename ios/Classes/{SwiftGeofencePlugin.swift => SwiftFlutterGeofencePlugin.swift} (79%) diff --git a/.gitignore b/.gitignore index 0d1970c..f2d285f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.idea /.packages /example/ios/Flutter/.last_build_id +/flutter_geofence.iml diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..9e63b03 --- /dev/null +++ b/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: f30b7f4db93ee747cd727df747941a28ead25ff5 + channel: stable + +project_type: plugin diff --git a/android/build.gradle b/android/build.gradle index c63b77c..4ad5893 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,4 +1,4 @@ -group 'com.intivoto.geofence' +group 'com.intivoto.flutter_geofence' version '1.0-SNAPSHOT' buildscript { @@ -32,7 +32,6 @@ android { } defaultConfig { minSdkVersion 16 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { disable 'InvalidPackage' diff --git a/android/gradle.properties b/android/gradle.properties index 38c8d45..94adc3a 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,4 +1,3 @@ org.gradle.jvmargs=-Xmx1536M -android.enableR8=true android.useAndroidX=true android.enableJetifier=true diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 019065d..01a286e 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-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/android/settings.gradle b/android/settings.gradle index 9685e0e..c3c6f54 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1 +1 @@ -rootProject.name = 'geofence' +rootProject.name = 'flutter_geofence' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 3d91ff5..e675ee1 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + package="com.intivoto.flutter_geofence"> diff --git a/android/src/main/kotlin/com/intivoto/flutter_geofence/FlutterGeofencePlugin.kt b/android/src/main/kotlin/com/intivoto/flutter_geofence/FlutterGeofencePlugin.kt new file mode 100644 index 0000000..0754380 --- /dev/null +++ b/android/src/main/kotlin/com/intivoto/flutter_geofence/FlutterGeofencePlugin.kt @@ -0,0 +1,194 @@ +package com.intivoto.flutter_geofence + +import android.Manifest +import android.annotation.SuppressLint +import android.app.Activity +import android.content.Context +import android.content.pm.PackageManager +import androidx.annotation.NonNull +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat + +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.embedding.engine.plugins.activity.ActivityAware +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result +import io.flutter.plugin.common.PluginRegistry + +/** FlutterGeofencePlugin */ +class FlutterGeofencePlugin : FlutterPlugin, MethodCallHandler, ActivityAware, PluginRegistry.RequestPermissionsResultListener { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private lateinit var channel: MethodChannel + private var geofenceManager: GeofenceManager? = null + private var currentActivity: Activity? = null + + + override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "geofence") + channel.setMethodCallHandler(this) + } + + override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { + if (call.method == "addRegion") { + val arguments = call.arguments as? HashMap<*, *> + if (arguments != null) { + val region = safeLet(arguments["id"] as? String, + arguments["radius"] as? Double, + arguments["lat"] as? Double, + arguments["lng"] as? Double, + arguments["event"] as? String) + { id, radius, latitude, longitude, event -> + GeoRegion( + id, + radius.toFloat(), + latitude, + longitude, + events = when (event) { + "GeolocationEvent.entry" -> listOf(GeoEvent.entry) + "GeolocationEvent.exit" -> listOf(GeoEvent.exit) + else -> GeoEvent.values().toList() + }) + } + if (region != null) { + geofenceManager?.startMonitoring(region) + result.success(null) + } else { + result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") + } + } else { + result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") + } + } else if (call.method == "removeRegion") { + val arguments = call.arguments as? HashMap<*, *> + if (arguments != null) { + val region = safeLet(arguments["id"] as? String, + arguments["radius"] as? Double, + arguments["lat"] as? Double, + arguments["lng"] as? Double, + arguments["event"] as? String) + { id, radius, latitude, longitude, event -> + GeoRegion( + id, + radius.toFloat(), + latitude, + longitude, + events = when (event) { + "GeolocationEvent.entry" -> listOf(GeoEvent.entry) + "GeolocationEvent.exit" -> listOf(GeoEvent.exit) + else -> GeoEvent.values().toList() + }) + } + if (region != null) { + geofenceManager?.stopMonitoring(region) + result.success(null) + } else { + result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") + } + } else { + result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") + } + } else if (call.method == "removeRegions") { + geofenceManager?.stopMonitoringAllRegions() + result.success(null) + } else if (call.method == "getUserLocation") { + geofenceManager?.getUserLocation() + result.success(null) + } else if (call.method == "requestPermissions") { + requestPermissions() + } else if (call.method == "startListeningForLocationChanges") { + geofenceManager?.startListeningForLocationChanges() + result.success(null) + } else if (call.method == "stopListeningForLocationChanges") { + geofenceManager?.stopListeningForLocationChanges() + result.success(null) + } else { + result.notImplemented() + } + } + + private fun requestPermissions() { + safeLet(currentActivity, currentActivity?.applicationContext) { activity, context -> + checkPermissions(context, activity) + } + } + + @SuppressLint("InlinedApi") + private fun checkPermissions(context: Context, activity: Activity) { + // Here, thisActivity is the current activity + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) + != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, + Manifest.permission.ACCESS_COARSE_LOCATION) + != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, + Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(activity, + arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION), + 999) + } else { + // Permission has already been granted + startGeofencing(context) + } + } + + private fun startGeofencing(context: Context) { + context.let { + geofenceManager = GeofenceManager(it, { + handleGeofenceEvent(it) + }, { + channel.invokeMethod("userLocationUpdated", hashMapOf("lat" to it.latitude, "lng" to it.longitude)) + }, { + channel.invokeMethod("backgroundLocationUpdated", hashMapOf("lat" to it.latitude, "lng" to it.longitude)) + }) + } + } + + private fun handleGeofenceEvent(region: GeoRegion) { + if (region.events.contains(GeoEvent.entry)) { + channel.invokeMethod("entry", region.serialized()) + } else { + channel.invokeMethod("exit", region.serialized()) + } + } + + override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + currentActivity = binding.activity + binding.addRequestPermissionsResultListener(this) + } + + override fun onDetachedFromActivityForConfigChanges() { + currentActivity = null + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + currentActivity = binding.activity + binding.addRequestPermissionsResultListener(this) + } + + override fun onDetachedFromActivity() { + currentActivity = null + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array?, grantResults: IntArray?): Boolean = + when (requestCode) { + 999 -> { + if (grantResults != null && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + currentActivity?.let { + startGeofencing(it.applicationContext) + } + true + } else { + false + } + } else -> false + } +} \ No newline at end of file diff --git a/android/src/main/kotlin/com/intivoto/geofence/GeofenceBroadcastReceiver.kt b/android/src/main/kotlin/com/intivoto/flutter_geofence/GeofenceBroadcastReceiver.kt similarity index 97% rename from android/src/main/kotlin/com/intivoto/geofence/GeofenceBroadcastReceiver.kt rename to android/src/main/kotlin/com/intivoto/flutter_geofence/GeofenceBroadcastReceiver.kt index 8dcaf89..657abcf 100644 --- a/android/src/main/kotlin/com/intivoto/geofence/GeofenceBroadcastReceiver.kt +++ b/android/src/main/kotlin/com/intivoto/flutter_geofence/GeofenceBroadcastReceiver.kt @@ -1,4 +1,4 @@ -package com.intivoto.geofence +package com.intivoto.flutter_geofence import android.content.BroadcastReceiver import android.content.Context diff --git a/android/src/main/kotlin/com/intivoto/geofence/GeofenceManager.kt b/android/src/main/kotlin/com/intivoto/flutter_geofence/GeofenceManager.kt similarity index 99% rename from android/src/main/kotlin/com/intivoto/geofence/GeofenceManager.kt rename to android/src/main/kotlin/com/intivoto/flutter_geofence/GeofenceManager.kt index cb475e7..c902024 100644 --- a/android/src/main/kotlin/com/intivoto/geofence/GeofenceManager.kt +++ b/android/src/main/kotlin/com/intivoto/flutter_geofence/GeofenceManager.kt @@ -1,4 +1,4 @@ -package com.intivoto.geofence +package com.intivoto.flutter_geofence import android.app.PendingIntent import android.content.Context diff --git a/android/src/main/kotlin/com/intivoto/geofence/SafeLet.kt b/android/src/main/kotlin/com/intivoto/flutter_geofence/SafeLet.kt similarity index 95% rename from android/src/main/kotlin/com/intivoto/geofence/SafeLet.kt rename to android/src/main/kotlin/com/intivoto/flutter_geofence/SafeLet.kt index ef734b5..a873c8e 100644 --- a/android/src/main/kotlin/com/intivoto/geofence/SafeLet.kt +++ b/android/src/main/kotlin/com/intivoto/flutter_geofence/SafeLet.kt @@ -1,4 +1,4 @@ -package com.intivoto.geofence +package com.intivoto.flutter_geofence fun safeLet(p1: T1?, p2: T2?, block: (T1, T2)->R?): R? { return if (p1 != null && p2 != null) block(p1, p2) else null diff --git a/android/src/main/kotlin/com/intivoto/geofence/GeofencePlugin.kt b/android/src/main/kotlin/com/intivoto/geofence/GeofencePlugin.kt deleted file mode 100644 index c8c4dbc..0000000 --- a/android/src/main/kotlin/com/intivoto/geofence/GeofencePlugin.kt +++ /dev/null @@ -1,205 +0,0 @@ -package com.intivoto.geofence - -import android.Manifest -import android.app.Activity -import android.content.Context -import android.content.pm.PackageManager -import androidx.annotation.NonNull -import androidx.core.app.ActivityCompat -import androidx.core.content.ContextCompat -import io.flutter.embedding.engine.plugins.FlutterPlugin -import io.flutter.embedding.engine.plugins.activity.ActivityAware -import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding -import io.flutter.plugin.common.MethodCall -import io.flutter.plugin.common.MethodChannel -import io.flutter.plugin.common.MethodChannel.MethodCallHandler -import io.flutter.plugin.common.MethodChannel.Result -import io.flutter.plugin.common.PluginRegistry.Registrar - -/** GeofencePlugin */ -public class GeofencePlugin : FlutterPlugin, MethodCallHandler, ActivityAware { - - override fun onDetachedFromActivity() { - } - - override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { - } - - override fun onAttachedToActivity(activityPluginBinding: ActivityPluginBinding) { - activityPluginBinding.addRequestPermissionsResultListener { requestCode, permissions, grantResults -> - if (requestCode == 999 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - startGeofencing(activityPluginBinding.activity.applicationContext) - return@addRequestPermissionsResultListener true - } - - return@addRequestPermissionsResultListener false - } - - setupPermissions(activityPluginBinding.activity, activityPluginBinding.activity.applicationContext) - } - - override fun onDetachedFromActivityForConfigChanges() { - } - - override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { - val channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "geofence") - channel.setMethodCallHandler(GeofencePlugin()) - GeofencePlugin.channel = channel - print("on attached called") - } - - companion object { - private var geofenceManager: GeofenceManager? = null - private var channel: MethodChannel? = null - private var registrar: Registrar? = null - private var activity: Activity? = null - private var context: Context? = null - - @JvmStatic - fun registerWith(registrar: Registrar) { - val channel = MethodChannel(registrar.messenger(), "geofence") - channel.setMethodCallHandler(GeofencePlugin()) - GeofencePlugin.channel = channel - - registrar.addRequestPermissionsResultListener { requestCode, permissions, grantResults -> - if (requestCode == 999 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - this.startGeofencing(registrar.activity().applicationContext) - return@addRequestPermissionsResultListener true - } - - return@addRequestPermissionsResultListener false - } - - setupPermissions(registrar.activity(), registrar.activeContext().applicationContext) - } - - fun setupPermissions(activity: Activity, context: Context) { - this.activity = activity - this.context = context - } - - fun requestPermissions() { - safeLet(activity, context) { activity, context -> - checkPermissions(context, activity) - } - } - - fun startGeofencing(context: Context) { - context.let { - geofenceManager = GeofenceManager(it, { - handleGeofenceEvent(it) - }, { - channel?.invokeMethod("userLocationUpdated", hashMapOf("lat" to it.latitude, "lng" to it.longitude)) - }, { - channel?.invokeMethod("backgroundLocationUpdated", hashMapOf("lat" to it.latitude, "lng" to it.longitude)) - }) - } - } - - private fun handleGeofenceEvent(region: GeoRegion) { - if (region.events.contains(GeoEvent.entry)) { - channel?.invokeMethod("entry", region.serialized()) - } else { - channel?.invokeMethod("exit", region.serialized()) - } - } - - private fun checkPermissions(context: Context, activity: Activity) { - // Here, thisActivity is the current activity - if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) - != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, - Manifest.permission.ACCESS_COARSE_LOCATION) - != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, - Manifest.permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(activity, - arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION), - 999) - } else { - // Permission has already been granted - startGeofencing(context) - } - } - } - - override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result): Unit = - if (call.method == "addRegion") { - val arguments = call.arguments as? HashMap<*, *> - if (arguments != null) { - val region = safeLet(arguments["id"] as? String, - arguments["radius"] as? Double, - arguments["lat"] as? Double, - arguments["lng"] as? Double, - arguments["event"] as? String) - { id, radius, latitude, longitude, event -> - GeoRegion( - id, - radius.toFloat(), - latitude, - longitude, - events = when (event) { - "GeolocationEvent.entry" -> listOf(GeoEvent.entry) - "GeolocationEvent.exit" -> listOf(GeoEvent.exit) - else -> GeoEvent.values().toList() - }) - } - if (region != null) { - geofenceManager?.startMonitoring(region) - result.success(null) - } else { - result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") - } - } else { - result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") - } - } else if (call.method == "removeRegion") { - val arguments = call.arguments as? HashMap<*, *> - if (arguments != null) { - val region = safeLet(arguments["id"] as? String, - arguments["radius"] as? Double, - arguments["lat"] as? Double, - arguments["lng"] as? Double, - arguments["event"] as? String) - { id, radius, latitude, longitude, event -> - GeoRegion( - id, - radius.toFloat(), - latitude, - longitude, - events = when (event) { - "GeolocationEvent.entry" -> listOf(GeoEvent.entry) - "GeolocationEvent.exit" -> listOf(GeoEvent.exit) - else -> GeoEvent.values().toList() - }) - } - if (region != null) { - geofenceManager?.stopMonitoring(region) - result.success(null) - } else { - result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") - } - } else { - result.error("Invalid arguments", "Has invalid arguments", "Has invalid arguments") - } - } else if (call.method == "removeRegions") { - geofenceManager?.stopMonitoringAllRegions() - result.success(null) - } else if (call.method == "getUserLocation") { - geofenceManager?.getUserLocation() - result.success(null) - } else if (call.method == "requestPermissions") { - requestPermissions() - } else if (call.method == "startListeningForLocationChanges") { - geofenceManager?.startListeningForLocationChanges() - result.success(null) - } else if (call.method == "stopListeningForLocationChanges") { - geofenceManager?.stopListeningForLocationChanges() - result.success(null) - } else { - result.notImplemented() - } - - override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { - - } -} \ No newline at end of file diff --git a/example/android/app/src/main/kotlin/com/intivoto/flutter_geofence_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/intivoto/flutter_geofence_example/MainActivity.kt new file mode 100644 index 0000000..2635ec2 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/intivoto/flutter_geofence_example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.intivoto.flutter_geofence_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 4f1190f..85863ab 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -381,7 +381,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = biz.waowdeals.geofenceExample; + PRODUCT_BUNDLE_IDENTIFIER = com.intivoto.geofenceExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -514,7 +514,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = biz.waowdeals.geofenceExample; + PRODUCT_BUNDLE_IDENTIFIER = com.intivoto.geofenceExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -542,7 +542,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = biz.waowdeals.geofenceExample; + PRODUCT_BUNDLE_IDENTIFIER = com.intivoto.geofenceExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/example/pubspec.lock b/example/pubspec.lock index 9a38aa3..6f98d0d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.4.0" flutter_local_notifications: dependency: "direct main" description: diff --git a/ios/Classes/FlutterGeofencePlugin.h b/ios/Classes/FlutterGeofencePlugin.h new file mode 100644 index 0000000..8b7a8e5 --- /dev/null +++ b/ios/Classes/FlutterGeofencePlugin.h @@ -0,0 +1,4 @@ +#import + +@interface FlutterGeofencePlugin : NSObject +@end diff --git a/ios/Classes/GeofencePlugin.m b/ios/Classes/FlutterGeofencePlugin.m similarity index 77% rename from ios/Classes/GeofencePlugin.m rename to ios/Classes/FlutterGeofencePlugin.m index 83ba4ca..76b02b5 100644 --- a/ios/Classes/GeofencePlugin.m +++ b/ios/Classes/FlutterGeofencePlugin.m @@ -1,4 +1,4 @@ -#import "GeofencePlugin.h" +#import "FlutterGeofencePlugin.h" #if __has_include() #import #else @@ -8,8 +8,8 @@ #import "flutter_geofence-Swift.h" #endif -@implementation GeofencePlugin +@implementation FlutterGeofencePlugin + (void)registerWithRegistrar:(NSObject*)registrar { - [SwiftGeofencePlugin registerWithRegistrar:registrar]; + [SwiftFlutterGeofencePlugin registerWithRegistrar:registrar]; } @end diff --git a/ios/Classes/GeofencePlugin.h b/ios/Classes/GeofencePlugin.h deleted file mode 100644 index 31888e0..0000000 --- a/ios/Classes/GeofencePlugin.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface GeofencePlugin : NSObject -@end diff --git a/ios/Classes/SwiftGeofencePlugin.swift b/ios/Classes/SwiftFlutterGeofencePlugin.swift similarity index 79% rename from ios/Classes/SwiftGeofencePlugin.swift rename to ios/Classes/SwiftFlutterGeofencePlugin.swift index 6d394d4..57d4c60 100644 --- a/ios/Classes/SwiftGeofencePlugin.swift +++ b/ios/Classes/SwiftFlutterGeofencePlugin.swift @@ -1,13 +1,13 @@ import Flutter import UIKit -public class SwiftGeofencePlugin: NSObject, FlutterPlugin { +public class SwiftFlutterGeofencePlugin: NSObject, FlutterPlugin { private var geofenceManager: GeofenceManager! private var channel: FlutterMethodChannel public static func register(with registrar: FlutterPluginRegistrar) { let channel = FlutterMethodChannel(name: "geofence", binaryMessenger: registrar.messenger()) - let instance = SwiftGeofencePlugin(channel: channel) + let instance = SwiftFlutterGeofencePlugin(channel: channel) registrar.addMethodCallDelegate(instance, channel: channel) } @@ -15,21 +15,21 @@ public class SwiftGeofencePlugin: NSObject, FlutterPlugin { self.channel = channel super.init() self.geofenceManager = GeofenceManager(callback: { [weak self] (region) in - self?.handleGeofenceEvent(region: region) - }, locationUpdate: { [weak self] (coordinate) in - self?.channel.invokeMethod("userLocationUpdated", arguments: ["lat": coordinate.latitude, "lng": coordinate.longitude]) - }, backgroundLocationUpdated: { [weak self] (coordinate) in - self?.channel.invokeMethod("backgroundLocationUpdated", arguments: ["lat": coordinate.latitude, "lng": coordinate.longitude]) - }) + self?.handleGeofenceEvent(region: region) + }, locationUpdate: { [weak self] (coordinate) in + self?.channel.invokeMethod("userLocationUpdated", arguments: ["lat": coordinate.latitude, "lng": coordinate.longitude]) + }, backgroundLocationUpdated: { [weak self] (coordinate) in + self?.channel.invokeMethod("backgroundLocationUpdated", arguments: ["lat": coordinate.latitude, "lng": coordinate.longitude]) + }) } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { if (call.method == "addRegion") { guard let arguments = call.arguments as? [AnyHashable: Any] else { return } guard let identifier = arguments["id"] as? String, - let latitude = arguments["lat"] as? Double, - let longitude = arguments["lng"] as? Double else { - return + let latitude = arguments["lat"] as? Double, + let longitude = arguments["lng"] as? Double else { + return } let radius = arguments["radius"] as? Double let event = arguments["event"] as? String @@ -38,9 +38,9 @@ public class SwiftGeofencePlugin: NSObject, FlutterPlugin { } else if (call.method == "removeRegion") { guard let arguments = call.arguments as? [AnyHashable: Any] else { return } guard let identifier = arguments["id"] as? String, - let latitude = arguments["lat"] as? Double, - let longitude = arguments["lng"] as? Double else { - return + let latitude = arguments["lat"] as? Double, + let longitude = arguments["lng"] as? Double else { + return } let radius = arguments["radius"] as? Double let event = arguments["event"] as? String diff --git a/pubspec.lock b/pubspec.lock index cd6330d..b03d310 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -144,4 +144,4 @@ packages: version: "2.1.0-nullsafety.3" sdks: dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.10.0 <2.0.0" + flutter: ">=1.12.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9bb096c..0e3c1c1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/DwayneCoussement/geofence environment: sdk: ">=2.1.0 <3.0.0" - flutter: ">=1.10.0 <2.0.0" + flutter: ">=1.12.0 <2.0.0" dependencies: flutter: @@ -19,7 +19,7 @@ flutter: plugin: platforms: android: - package: com.intivoto.geofence - pluginClass: GeofencePlugin + package: com.intivoto.flutter_geofence + pluginClass: FlutterGeofencePlugin ios: - pluginClass: GeofencePlugin \ No newline at end of file + pluginClass: FlutterGeofencePlugin \ No newline at end of file