From 4166d15eeaf28ba152a1ce9e89bf142f16b5b706 Mon Sep 17 00:00:00 2001 From: Kenny Hu Date: Thu, 27 Jun 2024 13:30:23 -0400 Subject: [PATCH 1/6] have ios working --- CHANGELOG.md | 5 + android/build.gradle | 2 +- .../io/radar/flutter/RadarFlutterPlugin.java | 2 +- example/android/app/build.gradle | 2 +- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 25 ++++- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 2 + example/lib/main.dart | 79 +++++++++---- ios/Classes/RadarFlutterPlugin.m | 106 ++++++++++-------- ios/flutter_radar.podspec | 4 +- lib/flutter_radar.dart | 74 ++++++++++-- pubspec.yaml | 2 +- 14 files changed, 220 insertions(+), 89 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c81afbe..93574c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 3.10.0 + +- Bump iOS version from 3.9.14 to 3.13.5 +- Bump Android version from 3.9.0 to 3.13.2 + # 3.9.1 - Bump iOS version from 3.9.7 to 3.9.14 diff --git a/android/build.gradle b/android/build.gradle index 11eef99..700e6f2 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,7 +34,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.9.8' + implementation 'io.radar:sdk:3.13.2' implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.google.code.gson:gson:2.8.6' } diff --git a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java index 0ab9c9f..9b64869 100644 --- a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java +++ b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java @@ -324,7 +324,7 @@ private void initialize(MethodCall call, Result result) { String publishableKey = call.argument("publishableKey"); SharedPreferences.Editor editor = mContext.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE).edit(); editor.putString("x_platform_sdk_type", "Flutter"); - editor.putString("x_platform_sdk_version", "3.9.1"); + editor.putString("x_platform_sdk_version", "3.10.0"); editor.apply(); Radar.initialize(mContext, publishableKey); result.success(true); diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index fb4140f..750378f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -49,7 +49,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.9.8' + implementation 'io.radar:sdk:3.13.2' implementation "com.google.android.play:integrity:1.2.0" } } diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 4f8d4d2..8c6e561 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/example/ios/Podfile b/example/ios/Podfile index bfd60c4..b331c7b 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -platform :ios, '11.0' +platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 3c16ff9..9e54d3c 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -149,6 +149,7 @@ 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + 717FBB0054865DEA34CA9827 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -165,7 +166,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -208,10 +209,12 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -220,6 +223,23 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n"; }; + 717FBB0054865DEA34CA9827 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; 8AED107CD2EAE06C6755A899 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -244,6 +264,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 3db53b6..e67b280 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/main.dart b/example/lib/main.dart index 4cbeaaa..dcd0298 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -67,6 +67,11 @@ class _MyAppState extends State with WidgetsBindingObserver { print('📍📍 onToken: $res'); } + @pragma('vm:entry-point') + static void onLocationPermissionStatus(Map res) { + print('📍📍 onLocationPermissionStatus: $res'); + } + Future initRadar() async { Radar.initialize('prj_test_pk_0000000000000000000000000000000000000000'); Radar.setUserId('flutter'); @@ -83,21 +88,25 @@ class _MyAppState extends State with WidgetsBindingObserver { Radar.onEvents(onEvents); Radar.onLog(onLog); Radar.onToken(onToken); + Radar.onLocationPermissionStatus(onLocationPermissionStatus); - await Radar.requestPermissions(false); + //await Radar.requestPermissions(false); - await Radar.requestPermissions(true); - var permissionStatus = await Radar.getPermissionsStatus(); - if (permissionStatus != "DENIED") { - var b = await Radar.startTrackingCustom({ - ... Radar.presetResponsive, - "showBlueBar": true, - }); - //Radar.startTracking('continuous'); - - var c = await Radar.getTrackingOptions(); - print("Tracking options $c"); - } + //await Radar.requestPermissions(true); + // var permissionStatus = await Radar.getPermissionsStatus(); + // if (permissionStatus != "DENIED") { + // var b = await Radar.startTrackingCustom({ + // ... Radar.presetResponsive, + // "showBlueBar": true, + // }); + // //Radar.startTracking('continuous'); + + // var c = await Radar.getTrackingOptions(); + // print("Tracking options $c"); + // } + var permissionStatus = await Radar.getLocationPermissionStatus(); + print(permissionStatus); + //await Radar.requestForegroundLocationPermission(); } @override @@ -179,6 +188,30 @@ class _MyAppState extends State with WidgetsBindingObserver { print("completeTrip: $resp"); }, child: Text('completeTrip'), + ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () async { + Radar.requestForegroundLocationPermission(); + + }, + child: Text('get foreground'), + ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () async { + Radar.requestBackgroundLocationPermission(); + + }, + child: Text('get background'), + ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () async { + Radar.openAppSettings(); + + }, + child: Text('openAppSettings'), ), ElevatedButton( style: raisedButtonStyle, @@ -339,9 +372,16 @@ class _MyAppState extends State with WidgetsBindingObserver { ElevatedButton( style: raisedButtonStyle, onPressed: () { - Radar.startTrackingVerified(token: true); + Radar.startTrackingVerified(); }, - child: Text('startTrackingVerified(token: true)'), + child: Text('startTrackingVerified()'), + ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () { + Radar.stopTrackingVerified(); + }, + child: Text('stopTrackingVerified()'), ), ElevatedButton( style: raisedButtonStyle, @@ -378,14 +418,7 @@ class _MyAppState extends State with WidgetsBindingObserver { }, child: Text('trackVerified'), ), - ElevatedButton( - style: raisedButtonStyle, - onPressed: () async { - Map? resp = await Radar.trackVerifiedToken(); - print("trackVerifiedToken: $resp"); - }, - child: Text('trackVerifiedToken'), - ), + ElevatedButton( style: raisedButtonStyle, onPressed: () async { diff --git a/ios/Classes/RadarFlutterPlugin.m b/ios/Classes/RadarFlutterPlugin.m index 487b8fe..1b0e4bd 100644 --- a/ios/Classes/RadarFlutterPlugin.m +++ b/ios/Classes/RadarFlutterPlugin.m @@ -74,6 +74,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self startTrackingCustom:call withResult:result]; } else if ([@"startTrackingVerified" isEqualToString:call.method]) { [self startTrackingVerified:call withResult:result]; + } else if ([@"stopTrackingVerified" isEqualToString:call.method]) { + [self stopTrackingVerified:call withResult:result]; } else if ([@"stopTracking" isEqualToString:call.method]) { [self stopTracking:call withResult:result]; } else if ([@"isTracking" isEqualToString:call.method]) { @@ -124,12 +126,18 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { // do nothing } else if ([@"trackVerified" isEqualToString:call.method]) { [self trackVerified:call withResult:result]; - } else if ([@"trackVerifiedToken" isEqualToString:call.method]) { - [self trackVerifiedToken:call withResult:result]; } else if ([@"isUsingRemoteTrackingOptions" isEqualToString:call.method]) { [self isUsingRemoteTrackingOptions:call withResult:result]; } else if ([@"validateAddress" isEqualToString:call.method]) { - [self validateAddress:call withResult:result]; + [self validateAddress:call withResult:result]; + } else if ([@"getLocationPermissionStatus" isEqualToString:call.method]) { + [self getLocationPermissionStatus:result]; + } else if ([@"requestForegroundLocationPermission" isEqualToString:call.method]) { + [self requestForegroundLocationPermission:result]; + } else if ([@"requestBackgroundLocationPermission" isEqualToString:call.method]) { + [self requestBackgroundLocationPermission:result]; + } else if ([@"openAppSettings" isEqualToString:call.method]) { + [self openAppSettings:result]; } else if ([@"attachListeners" isEqualToString:call.method]) { [self attachListeners:call withResult:result]; } else if ([@"detachListeners" isEqualToString:call.method]) { @@ -148,7 +156,7 @@ - (void)initialize:(FlutterMethodCall *)call withResult:(FlutterResult)result { NSString *publishableKey = argsDict[@"publishableKey"]; [[NSUserDefaults standardUserDefaults] setObject:@"Flutter" forKey:@"radar-xPlatformSDKType"]; - [[NSUserDefaults standardUserDefaults] setObject:@"3.9.1" forKey:@"radar-xPlatformSDKVersion"]; + [[NSUserDefaults standardUserDefaults] setObject:@"3.10.0" forKey:@"radar-xPlatformSDKVersion"]; [Radar initializeWithPublishableKey:publishableKey]; result(nil); } @@ -379,12 +387,6 @@ - (void)startTrackingCustom:(FlutterMethodCall *)call withResult:(FlutterResult) - (void)startTrackingVerified:(FlutterMethodCall *)call withResult:(FlutterResult)result { NSDictionary *argsDict = call.arguments; - BOOL token = NO; - NSNumber *tokenNumber = argsDict[@"token"]; - if (tokenNumber != nil && [tokenNumber isKindOfClass:[NSNumber class]]) { - token = [tokenNumber boolValue]; - } - BOOL beacons = NO; NSNumber *beaconsNumber = argsDict[@"beacons"]; if (beaconsNumber != nil && [beaconsNumber isKindOfClass:[NSNumber class]]) { @@ -397,7 +399,12 @@ - (void)startTrackingVerified:(FlutterMethodCall *)call withResult:(FlutterResul interval = [intervalNumber doubleValue]; } - [Radar startTrackingVerified:token interval:interval beacons:beacons]; + [Radar startTrackingVerifiedWithInterval:interval beacons:beacons]; + result(nil); +} + +- (void)stopTrackingVerified:(FlutterMethodCall *)call withResult:(FlutterResult)result { + [Radar stopTrackingVerified]; result(nil); } @@ -639,11 +646,17 @@ - (void)searchGeofences:(FlutterMethodCall *)call withResult:(FlutterResult)resu } else { limit = 10; } + BOOL includeGeometry = NO; + NSNumber *includeGeometryNumber = argsDict[@"includeGeometry"]; + if (includeGeometryNumber != nil && [includeGeometryNumber isKindOfClass:[NSNumber class]]) { + includeGeometry = [includeGeometryNumber boolValue]; + } + if (near != nil) { - [Radar searchGeofencesNear:near radius:radius tags:tags metadata:metadata limit:limit completionHandler:completionHandler]; + [Radar searchGeofencesNear:near radius:radius tags:tags metadata:metadata limit:limit includeGeometry:includeGeometry completionHandler:completionHandler]; } else { - [Radar searchGeofencesWithRadius:radius tags:tags metadata:metadata limit:limit completionHandler:completionHandler]; + [Radar searchGeofences:completionHandler]; } } @@ -956,19 +969,11 @@ - (void)trackVerified:(FlutterMethodCall *)call withResult:(FlutterResult)result beacons = [beaconsNumber boolValue]; } - RadarTrackCompletionHandler completionHandler = ^(RadarStatus status, CLLocation *location, NSArray *events, RadarUser *user) { + RadarTrackVerifiedCompletionHandler completionHandler = ^(RadarStatus status, RadarVerifiedLocationToken* token) { if (status == RadarStatusSuccess) { NSMutableDictionary *dict = [NSMutableDictionary new]; [dict setObject:[Radar stringForStatus:status] forKey:@"status"]; - if (location) { - [dict setObject:[Radar dictionaryForLocation:location] forKey:@"location"]; - } - if (events) { - [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"]; - } - if (user) { - [dict setObject:[user dictionaryValue] forKey:@"user"]; - } + [dict setObject:[token dictionaryValue] forKey:@"token"]; result(dict); } }; @@ -976,27 +981,6 @@ - (void)trackVerified:(FlutterMethodCall *)call withResult:(FlutterResult)result [Radar trackVerifiedWithBeacons:beacons completionHandler:completionHandler]; } -- (void)trackVerifiedToken:(FlutterMethodCall *)call withResult:(FlutterResult)result { - NSDictionary *argsDict = call.arguments; - - BOOL beacons = NO; - NSNumber *beaconsNumber = argsDict[@"beacons"]; - if (beaconsNumber != nil && [beaconsNumber isKindOfClass:[NSNumber class]]) { - beacons = [beaconsNumber boolValue]; - } - - RadarTrackTokenCompletionHandler completionHandler = ^(RadarStatus status, NSString* token) { - if (status == RadarStatusSuccess) { - NSMutableDictionary *dict = [NSMutableDictionary new]; - [dict setObject:[Radar stringForStatus:status] forKey:@"status"]; - [dict setObject:token forKey:@"token"]; - result(dict); - } - }; - - [Radar trackVerifiedTokenWithBeacons:beacons completionHandler:completionHandler]; -} - - (void)validateAddress:(FlutterMethodCall *)call withResult:(FlutterResult)result { RadarValidateAddressCompletionHandler completionHandler = ^(RadarStatus status, RadarAddress * _Nullable address, RadarAddressVerificationStatus verificationStatus) { NSMutableDictionary *dict = [NSMutableDictionary new]; @@ -1015,6 +999,26 @@ - (void)validateAddress:(FlutterMethodCall *)call withResult:(FlutterResult)resu [Radar validateAddress:address completionHandler:completionHandler]; } +-(void)requestForegroundLocationPermission:(FlutterResult)result { + [Radar requestForegroundLocationPermission]; + result(nil); +} + +-(void)requestBackgroundLocationPermission:(FlutterResult)result { + [Radar requestBackgroundLocationPermission]; + result(nil); +} + +-(void)getLocationPermissionStatus:(FlutterResult)result { + RadarLocationPermissionStatus *status = [Radar getLocationPermissionStatus]; + result([status dictionaryValue]); +} + +-(void)openAppSettings:(FlutterResult)result { + [Radar openAppSettings]; + result(nil); +} + -(void)attachListeners:(FlutterMethodCall *)call withResult:(FlutterResult)result { NSNumber* callbackDispatcherHandle = call.arguments[@"callbackDispatcherHandle"]; @@ -1122,6 +1126,20 @@ - (void)didUpdateToken:(NSString *)token { [self.backgroundChannel invokeMethod:@"" arguments:args]; } +- (void)didUpdateLocationPermissionStatus:(RadarLocationPermissionStatus *)status { + NSDictionary *dict = @{@"status": [status dictionaryValue]}; + NSLog(@"didUpdateLocationPermissionStatus"); + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + NSNumber* callbackHandle = [userDefaults objectForKey:@"locationPermissionStatus"]; + if (callbackHandle == 0) { + NSLog(@"callbackHandle is 0"); + return; + } + NSLog(@"calling background channel"); + NSArray* args = @[callbackHandle, dict]; + [self.backgroundChannel invokeMethod:@"" arguments:args]; +} + @end @implementation RadarStreamHandler diff --git a/ios/flutter_radar.podspec b/ios/flutter_radar.podspec index 63f63da..cd36ca3 100644 --- a/ios/flutter_radar.podspec +++ b/ios/flutter_radar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'flutter_radar' - s.version = '3.9.1' + s.version = '3.10.0' s.summary = 'Flutter package for Radar, the leading geofencing and location tracking platform' s.description = 'Flutter package for Radar, the leading geofencing and location tracking platform' s.homepage = 'http://example.com' @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'RadarSDK', '3.9.14' + s.dependency 'RadarSDK', '3.13.5' s.platform = :ios, '10.0' s.static_framework = true diff --git a/lib/flutter_radar.dart b/lib/flutter_radar.dart index c344a86..81326c5 100644 --- a/lib/flutter_radar.dart +++ b/lib/flutter_radar.dart @@ -163,10 +163,10 @@ class Radar { } static Future startTrackingVerified( - {bool? token, int? interval, bool? beacons}) async { + {int? interval, bool? beacons}) async { try { await _channel.invokeMethod('startTrackingVerified', - {'token': token, 'interval': interval, 'beacons': beacons}); + {'interval': interval, 'beacons': beacons}); } on PlatformException catch (e) { print(e); } @@ -180,6 +180,14 @@ class Radar { } } + static Future stopTrackingVerified() async { + try { + await _channel.invokeMethod('stopTrackingVerified'); + } on PlatformException catch (e) { + print(e); + } + } + static Future isTracking() async { return await _channel.invokeMethod('isTracking'); } @@ -272,14 +280,16 @@ class Radar { int? radius, List? tags, Map? metadata, - int? limit}) async { + int? limit, + bool? includeGeometry}) async { try { return await _channel.invokeMethod('searchGeofences', { 'near': near, 'radius': radius, 'limit': limit, 'tags': tags, - 'metadata': metadata + 'metadata': metadata, + 'includeGeometry': includeGeometry }); } on PlatformException catch (e) { print(e); @@ -467,24 +477,47 @@ class Radar { } } - static Future trackVerifiedToken({bool? beacons}) async { + static Future isUsingRemoteTrackingOptions() async { + return await _channel.invokeMethod('isUsingRemoteTrackingOptions'); + } + + static Future validateAddress(Map address) async { try { return await _channel - .invokeMethod('trackVerifiedToken', {'beacons': beacons}); + .invokeMethod('validateAddress', {'address': address}); } on PlatformException catch (e) { print(e); return {'error': e.code}; } } - static Future isUsingRemoteTrackingOptions() async { - return await _channel.invokeMethod('isUsingRemoteTrackingOptions'); + static Future requestForegroundLocationPermission() async { + try { + await _channel.invokeMethod('requestForegroundLocationPermission'); + } on PlatformException catch (e) { + print(e); + } } - static Future validateAddress(Map address) async { + static Future requestBackgroundLocationPermission() async { try { - return await _channel - .invokeMethod('validateAddress', {'address': address}); + await _channel.invokeMethod('requestBackgroundLocationPermission'); + } on PlatformException catch (e) { + print(e); + } + } + + static Future openAppSettings() async { + try { + await _channel.invokeMethod('openAppSettings'); + } on PlatformException catch (e) { + print(e); + } + } + + static Future getLocationPermissionStatus() async { + try { + return await _channel.invokeMethod('getLocationPermissionStatus'); } on PlatformException catch (e) { print(e); return {'error': e.code}; @@ -607,6 +640,25 @@ class Radar { } } + static onLocationPermissionStatus(Function(Map res) callback) async { + try { + final CallbackHandle handle = + PluginUtilities.getCallbackHandle(callback)!; + await _channel.invokeMethod( + 'on', {'listener': 'locationPermissionStatus', 'callbackHandle': handle.toRawHandle()}); + } on PlatformException catch (e) { + print(e); + } + } + + static offLocationPermissionStatus() async { + try { + await _channel.invokeMethod('off', {'listener': 'locationPermissionStatus'}); + } on PlatformException catch (e) { + print(e); + } + } + static Map presetContinuousIOS = { "desiredStoppedUpdateInterval": 30, "desiredMovingUpdateInterval": 30, diff --git a/pubspec.yaml b/pubspec.yaml index 482f01e..2b48bb1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_radar description: Flutter package for Radar, the leading geofencing and location tracking platform -version: 3.9.1 +version: 3.10.0 homepage: https://github.com/radarlabs/flutter-radar environment: From 3f200d94eadab97f5c0c3c4874a9b64c25fbb6a7 Mon Sep 17 00:00:00 2001 From: Kenny Hu Date: Thu, 27 Jun 2024 15:00:06 -0400 Subject: [PATCH 2/6] draft android --- CHANGELOG.md | 2 +- android/build.gradle | 2 +- .../io/radar/flutter/RadarFlutterPlugin.java | 131 ++++++++++++------ example/android/app/build.gradle | 4 +- example/android/build.gradle | 2 +- example/lib/main.dart | 10 +- lib/flutter_radar.dart | 3 +- 7 files changed, 100 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93574c5..bc2bb82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # 3.10.0 - Bump iOS version from 3.9.14 to 3.13.5 -- Bump Android version from 3.9.0 to 3.13.2 +- Bump Android version from 3.9.8 to 3.13.2 # 3.9.1 diff --git a/android/build.gradle b/android/build.gradle index 700e6f2..5ceee60 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,7 +34,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.13.2' + implementation 'io.radar:sdk:3.13.1' implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.google.code.gson:gson:2.8.6' } diff --git a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java index 9b64869..c9175c3 100644 --- a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java +++ b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java @@ -57,7 +57,9 @@ import io.radar.sdk.model.RadarUser; import io.radar.sdk.model.RadarTrip; import io.radar.sdk.model.RadarRouteMatrix; +import io.radar.sdk.model.RadarLocationPermissionStatus; import io.radar.sdk.RadarTrackingOptions.RadarTrackingOptionsForegroundService; +import io.radar.sdk.model.RadarVerifiedLocationToken; import io.flutter.embedding.engine.dart.DartExecutor; import io.flutter.embedding.engine.dart.DartExecutor.DartCallback; @@ -215,6 +217,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) case "startTrackingVerified": startTrackingVerified(call, result); break; + case "stopTrackingVerified": + stopTrackingVerified(call, result); + break; case "stopTracking": stopTracking(result); break; @@ -293,12 +298,21 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) case "trackVerified": trackVerified(call, result); break; - case "trackVerifiedToken": - trackVerifiedToken(call, result); - break; case "validateAddress": validateAddress(call, result); break; + case "requestForegroundLocationPermission": + requestForegroundLocationPermission(result); + break; + case "requestBackgroundLocationPermission": + requestBackgroundLocationPermission(result); + break; + case "openAppSettings": + openAppSettings(result); + break; + case "getLocationPermissionStatus": + getLocationPermissionStatus(result); + break; case "attachListeners": attachListeners(call, result); break; @@ -569,10 +583,14 @@ private void startTrackingCustom(MethodCall call, Result result) { } private void startTrackingVerified(MethodCall call, Result result) { - Boolean token = call.hasArgument("token") ? call.argument("token") : false; int interval = call.hasArgument("interval") && call.argument("interval") != null ? (int)call.argument("interval") : 1; Boolean beacons = call.hasArgument("beacons") ? call.argument("beacons") : false; - Radar.startTrackingVerified(token, interval, beacons); + Radar.startTrackingVerified(interval, beacons); + result.success(true); + } + + private void stopTrackingVerified(MethodCall call, Result result) { + Radar.stopTrackingVerified(); result.success(true); } @@ -848,11 +866,12 @@ public void run() { HashMap metadataMap = (HashMap)call.argument("metadata"); JSONObject metadata = jsonForMap(metadataMap); int limit = call.hasArgument("limit") ? (int)call.argument("limit") : 10; + boolean includeGeometry = call.hasArgument("includeGeometry") ? call.argument("includeGeometry") : false; if (near != null) { - Radar.searchGeofences(near, radius, tags, metadata, limit, callback); + Radar.searchGeofences(near, radius, tags, metadata, limit, includeGeometry, callback); } else { - Radar.searchGeofences(radius, tags, metadata, limit, callback); + Radar.searchGeofences(radius, tags, metadata, limit, includeGeometry, callback); } } @@ -942,7 +961,7 @@ public void run() { public void geocode(MethodCall call, final Result result) { String query = call.argument("query"); - Radar.geocode(query, new Radar.RadarGeocodeCallback() { + Radar.geocode(query, null, null, new Radar.RadarGeocodeCallback() { @Override public void onComplete(final Radar.RadarStatus status, final RadarAddress[] addresses) { runOnMainThread(new Runnable() { @@ -993,9 +1012,9 @@ public void run() { if (call.hasArgument("location")) { HashMap locationMap = (HashMap)call.argument("location"); Location location = locationForMap(locationMap); - Radar.reverseGeocode(location, callback); + Radar.reverseGeocode(location, null, callback); } else { - Radar.reverseGeocode(callback); + Radar.reverseGeocode(null ,callback); } } @@ -1182,22 +1201,16 @@ public void run() { public void trackVerified(MethodCall call, final Result result) { Boolean beacons = call.hasArgument("beacons") ? call.argument("beacons") : false; - Radar.RadarTrackCallback callback = new Radar.RadarTrackCallback() { + Radar.RadarTrackVerifiedCallback callback = new Radar.RadarTrackVerifiedCallback() { @Override - public void onComplete(final Radar.RadarStatus status, final Location location, final RadarEvent[] events, final RadarUser user) { + public void onComplete(final Radar.RadarStatus status, final RadarVerifiedLocationToken token) { runOnMainThread(new Runnable() { @Override public void run() { try { JSONObject obj = new JSONObject(); obj.put("status", status.toString()); - if (location != null) { - obj.put("location", Radar.jsonForLocation(location)); - } - obj.put("events", RadarEvent.toJson(events)); - if ( user != null) { - obj.put("user", user.toJson()); - } + obj.put("token", token.toJson()); HashMap map = new Gson().fromJson(obj.toString(), HashMap.class); result.success(map); @@ -1212,36 +1225,31 @@ public void run() { Radar.trackVerified(beacons, callback); } - public void trackVerifiedToken(MethodCall call, final Result result) { - Boolean beacons = call.hasArgument("beacons") ? call.argument("beacons") : false; + private void isUsingRemoteTrackingOptions(Result result) { + Boolean isRemoteTracking = Radar.isUsingRemoteTrackingOptions(); + result.success(isRemoteTracking); + } - Radar.RadarTrackTokenCallback callback = new Radar.RadarTrackTokenCallback() { - @Override - public void onComplete(final Radar.RadarStatus status, final String token) { - runOnMainThread(new Runnable() { - @Override - public void run() { - try { - JSONObject obj = new JSONObject(); - obj.put("status", status.toString()); - obj.put("token", token); + private void requestForegroundLocationPermission (Result result) { + Radar.requestForegroundLocationPermission(); + result.success(true); + } - HashMap map = new Gson().fromJson(obj.toString(), HashMap.class); - result.success(map); - } catch (Exception e) { - result.error(e.toString(), e.getMessage(), e.getMessage()); - } - } - }); - } - }; + private void requestBackgroundLocationPermission (Result result) { + Radar.requestBackgroundLocationPermission(); + result.success(true); + } - Radar.trackVerifiedToken(beacons, callback); + private void openAppSettings (Result result) { + Radar.openAppSettings(); + result.success(true); } - private void isUsingRemoteTrackingOptions(Result result) { - Boolean isRemoteTracking = Radar.isUsingRemoteTrackingOptions(); - result.success(isRemoteTracking); + private void getLocationPermissionStatus (Result result) { + RadarLocationPermissionStatus status = Radar.getLocationPermissionStatus(); + JSONObject obj = status.toJson(); + HashMap map = new Gson().fromJson(obj.toString(), HashMap.class); + result.success(map); } public void validateAddress(MethodCall call, final Result result) throws JSONException { @@ -1471,12 +1479,43 @@ public void run() { } } + @Override + public void onLocationPermissionStatusUpdated(Context context, RadarLocationPermissionStatus status) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); + long callbackHandle = sharedPrefs.getLong("locationPermissionStatus", 0L); + + if (callbackHandle == 0L) { + return; + } + + RadarFlutterPlugin.initializeBackgroundEngine(context); + + JSONObject obj = status.toJson(); + + HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); + synchronized(lock) { + final ArrayList args = new ArrayList(); + args.add(callbackHandle); + args.add(res); + runOnMainThread(new Runnable() { + @Override + public void run() { + sBackgroundChannel.invokeMethod("", args); + } + }); + } + } catch (Exception e) { + Log.e(TAG, e.toString()); + } + } + } public static class RadarFlutterVerifiedReceiver extends RadarVerifiedReceiver { @Override - public void onTokenUpdated(Context context, String token) { + public void onTokenUpdated(Context context, RadarVerifiedLocationToken token) { try { SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); long callbackHandle = sharedPrefs.getLong("token", 0L); @@ -1488,7 +1527,7 @@ public void onTokenUpdated(Context context, String token) { RadarFlutterPlugin.initializeBackgroundEngine(context); JSONObject obj = new JSONObject(); - obj.put("token", token); + obj.put("token", token.toJson()); HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); synchronized(lock) { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 750378f..bcfe3b3 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -34,7 +34,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "io.radar.example" - minSdkVersion 16 + minSdkVersion flutter.minSdkVersion targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName @@ -49,7 +49,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.13.2' + implementation 'io.radar:sdk:3.13.1' implementation "com.google.android.play:integrity:1.2.0" } } diff --git a/example/android/build.gradle b/example/android/build.gradle index 21d7749..9881192 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -24,6 +24,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/lib/main.dart b/example/lib/main.dart index dcd0298..1c7f274 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -213,6 +213,14 @@ class _MyAppState extends State with WidgetsBindingObserver { }, child: Text('openAppSettings'), ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () async { + var resp = await Radar.getLocationPermissionStatus(); + print("status: $resp"); + }, + child: Text('getLocationPermissionStatus'), + ), ElevatedButton( style: raisedButtonStyle, onPressed: () async { @@ -372,7 +380,7 @@ class _MyAppState extends State with WidgetsBindingObserver { ElevatedButton( style: raisedButtonStyle, onPressed: () { - Radar.startTrackingVerified(); + Radar.startTrackingVerified(30, false); }, child: Text('startTrackingVerified()'), ), diff --git a/lib/flutter_radar.dart b/lib/flutter_radar.dart index 81326c5..e33c7aa 100644 --- a/lib/flutter_radar.dart +++ b/lib/flutter_radar.dart @@ -162,8 +162,7 @@ class Radar { } } - static Future startTrackingVerified( - {int? interval, bool? beacons}) async { + static Future startTrackingVerified(int interval, bool beacons) async { try { await _channel.invokeMethod('startTrackingVerified', {'interval': interval, 'beacons': beacons}); From f34746cef6339a631cc956cba19a27c8eabd68f9 Mon Sep 17 00:00:00 2001 From: Kenny Hu Date: Tue, 16 Jul 2024 11:41:08 -0400 Subject: [PATCH 3/6] remove location permissions stuff --- android/build.gradle | 2 +- .../io/radar/flutter/RadarFlutterPlugin.java | 70 +----------------- example/android/app/build.gradle | 2 +- example/lib/main.dart | 71 ++++--------------- ios/Classes/RadarFlutterPlugin.m | 42 ----------- ios/flutter_radar.podspec | 2 +- 6 files changed, 19 insertions(+), 170 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 5ceee60..d305e1a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,7 +34,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.13.1' + implementation 'io.radar:sdk:3.14.0' implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.google.code.gson:gson:2.8.6' } diff --git a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java index c9175c3..f515b29 100644 --- a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java +++ b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java @@ -57,7 +57,6 @@ import io.radar.sdk.model.RadarUser; import io.radar.sdk.model.RadarTrip; import io.radar.sdk.model.RadarRouteMatrix; -import io.radar.sdk.model.RadarLocationPermissionStatus; import io.radar.sdk.RadarTrackingOptions.RadarTrackingOptionsForegroundService; import io.radar.sdk.model.RadarVerifiedLocationToken; @@ -106,7 +105,7 @@ private static void initializeBackgroundEngine(Context context) { } } } - + @Override public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { Radar.setReceiver(new RadarFlutterReceiver()); @@ -301,18 +300,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) case "validateAddress": validateAddress(call, result); break; - case "requestForegroundLocationPermission": - requestForegroundLocationPermission(result); - break; - case "requestBackgroundLocationPermission": - requestBackgroundLocationPermission(result); - break; - case "openAppSettings": - openAppSettings(result); - break; - case "getLocationPermissionStatus": - getLocationPermissionStatus(result); - break; case "attachListeners": attachListeners(call, result); break; @@ -1230,28 +1217,6 @@ private void isUsingRemoteTrackingOptions(Result result) { result.success(isRemoteTracking); } - private void requestForegroundLocationPermission (Result result) { - Radar.requestForegroundLocationPermission(); - result.success(true); - } - - private void requestBackgroundLocationPermission (Result result) { - Radar.requestBackgroundLocationPermission(); - result.success(true); - } - - private void openAppSettings (Result result) { - Radar.openAppSettings(); - result.success(true); - } - - private void getLocationPermissionStatus (Result result) { - RadarLocationPermissionStatus status = Radar.getLocationPermissionStatus(); - JSONObject obj = status.toJson(); - HashMap map = new Gson().fromJson(obj.toString(), HashMap.class); - result.success(map); - } - public void validateAddress(MethodCall call, final Result result) throws JSONException { Radar.RadarValidateAddressCallback callback = new Radar.RadarValidateAddressCallback() { @Override @@ -1348,39 +1313,6 @@ public void run() { } } - @Override - public void onLocationUpdated(Context context, Location location, RadarUser user) { - try { - SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); - long callbackHandle = sharedPrefs.getLong("location", 0L); - - if (callbackHandle == 0L) { - Log.e(TAG, "callback handle is empty"); - return; - } - - RadarFlutterPlugin.initializeBackgroundEngine(context); - - JSONObject obj = new JSONObject(); - obj.put("location", Radar.jsonForLocation(location)); - obj.put("user", user.toJson()); - - HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); - synchronized(lock) { - final ArrayList args = new ArrayList(); - args.add(callbackHandle); - args.add(res); - runOnMainThread(new Runnable() { - @Override - public void run() { - sBackgroundChannel.invokeMethod("", args); - } - }); - } - } catch (Exception e) { - Log.e(TAG, e.toString()); - } - } public void onClientLocationUpdated(Context context, Location location, boolean stopped, Radar.RadarLocationSource source) { try { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index bcfe3b3..59d7f02 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -49,7 +49,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.13.1' + implementation 'io.radar:sdk:3.14.0' implementation "com.google.android.play:integrity:1.2.0" } } diff --git a/example/lib/main.dart b/example/lib/main.dart index 1c7f274..61bb9b7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -67,11 +67,6 @@ class _MyAppState extends State with WidgetsBindingObserver { print('📍📍 onToken: $res'); } - @pragma('vm:entry-point') - static void onLocationPermissionStatus(Map res) { - print('📍📍 onLocationPermissionStatus: $res'); - } - Future initRadar() async { Radar.initialize('prj_test_pk_0000000000000000000000000000000000000000'); Radar.setUserId('flutter'); @@ -88,25 +83,21 @@ class _MyAppState extends State with WidgetsBindingObserver { Radar.onEvents(onEvents); Radar.onLog(onLog); Radar.onToken(onToken); - Radar.onLocationPermissionStatus(onLocationPermissionStatus); - - //await Radar.requestPermissions(false); - - //await Radar.requestPermissions(true); - // var permissionStatus = await Radar.getPermissionsStatus(); - // if (permissionStatus != "DENIED") { - // var b = await Radar.startTrackingCustom({ - // ... Radar.presetResponsive, - // "showBlueBar": true, - // }); - // //Radar.startTracking('continuous'); - - // var c = await Radar.getTrackingOptions(); - // print("Tracking options $c"); - // } - var permissionStatus = await Radar.getLocationPermissionStatus(); - print(permissionStatus); - //await Radar.requestForegroundLocationPermission(); + + await Radar.requestPermissions(false); + + await Radar.requestPermissions(true); + var permissionStatus = await Radar.getPermissionsStatus(); + if (permissionStatus != "DENIED") { + var b = await Radar.startTrackingCustom({ + ... Radar.presetResponsive, + "showBlueBar": true, + }); + //Radar.startTracking('continuous'); + + var c = await Radar.getTrackingOptions(); + print("Tracking options $c"); + } } @override @@ -188,38 +179,6 @@ class _MyAppState extends State with WidgetsBindingObserver { print("completeTrip: $resp"); }, child: Text('completeTrip'), - ), - ElevatedButton( - style: raisedButtonStyle, - onPressed: () async { - Radar.requestForegroundLocationPermission(); - - }, - child: Text('get foreground'), - ), - ElevatedButton( - style: raisedButtonStyle, - onPressed: () async { - Radar.requestBackgroundLocationPermission(); - - }, - child: Text('get background'), - ), - ElevatedButton( - style: raisedButtonStyle, - onPressed: () async { - Radar.openAppSettings(); - - }, - child: Text('openAppSettings'), - ), - ElevatedButton( - style: raisedButtonStyle, - onPressed: () async { - var resp = await Radar.getLocationPermissionStatus(); - print("status: $resp"); - }, - child: Text('getLocationPermissionStatus'), ), ElevatedButton( style: raisedButtonStyle, diff --git a/ios/Classes/RadarFlutterPlugin.m b/ios/Classes/RadarFlutterPlugin.m index 1b0e4bd..16dfa22 100644 --- a/ios/Classes/RadarFlutterPlugin.m +++ b/ios/Classes/RadarFlutterPlugin.m @@ -130,14 +130,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self isUsingRemoteTrackingOptions:call withResult:result]; } else if ([@"validateAddress" isEqualToString:call.method]) { [self validateAddress:call withResult:result]; - } else if ([@"getLocationPermissionStatus" isEqualToString:call.method]) { - [self getLocationPermissionStatus:result]; - } else if ([@"requestForegroundLocationPermission" isEqualToString:call.method]) { - [self requestForegroundLocationPermission:result]; - } else if ([@"requestBackgroundLocationPermission" isEqualToString:call.method]) { - [self requestBackgroundLocationPermission:result]; - } else if ([@"openAppSettings" isEqualToString:call.method]) { - [self openAppSettings:result]; } else if ([@"attachListeners" isEqualToString:call.method]) { [self attachListeners:call withResult:result]; } else if ([@"detachListeners" isEqualToString:call.method]) { @@ -999,26 +991,6 @@ - (void)validateAddress:(FlutterMethodCall *)call withResult:(FlutterResult)resu [Radar validateAddress:address completionHandler:completionHandler]; } --(void)requestForegroundLocationPermission:(FlutterResult)result { - [Radar requestForegroundLocationPermission]; - result(nil); -} - --(void)requestBackgroundLocationPermission:(FlutterResult)result { - [Radar requestBackgroundLocationPermission]; - result(nil); -} - --(void)getLocationPermissionStatus:(FlutterResult)result { - RadarLocationPermissionStatus *status = [Radar getLocationPermissionStatus]; - result([status dictionaryValue]); -} - --(void)openAppSettings:(FlutterResult)result { - [Radar openAppSettings]; - result(nil); -} - -(void)attachListeners:(FlutterMethodCall *)call withResult:(FlutterResult)result { NSNumber* callbackDispatcherHandle = call.arguments[@"callbackDispatcherHandle"]; @@ -1126,20 +1098,6 @@ - (void)didUpdateToken:(NSString *)token { [self.backgroundChannel invokeMethod:@"" arguments:args]; } -- (void)didUpdateLocationPermissionStatus:(RadarLocationPermissionStatus *)status { - NSDictionary *dict = @{@"status": [status dictionaryValue]}; - NSLog(@"didUpdateLocationPermissionStatus"); - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - NSNumber* callbackHandle = [userDefaults objectForKey:@"locationPermissionStatus"]; - if (callbackHandle == 0) { - NSLog(@"callbackHandle is 0"); - return; - } - NSLog(@"calling background channel"); - NSArray* args = @[callbackHandle, dict]; - [self.backgroundChannel invokeMethod:@"" arguments:args]; -} - @end @implementation RadarStreamHandler diff --git a/ios/flutter_radar.podspec b/ios/flutter_radar.podspec index cd36ca3..f9173c3 100644 --- a/ios/flutter_radar.podspec +++ b/ios/flutter_radar.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'RadarSDK', '3.13.5' + s.dependency 'RadarSDK', '3.14.0' s.platform = :ios, '10.0' s.static_framework = true From 87d68d1eb785127fa940fe018bf496c85c7cc888 Mon Sep 17 00:00:00 2001 From: Kenny Hu Date: Tue, 16 Jul 2024 12:08:14 -0400 Subject: [PATCH 4/6] bump version --- android/build.gradle | 2 +- .../io/radar/flutter/RadarFlutterPlugin.java | 44 ++++++++++--------- example/android/app/build.gradle | 2 +- ios/flutter_radar.podspec | 2 +- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index d305e1a..77e9a78 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,7 +34,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.14.0' + implementation 'io.radar:sdk:3.15.0' implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.google.code.gson:gson:2.8.6' } diff --git a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java index f515b29..6cafeb1 100644 --- a/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java +++ b/android/src/main/java/io/radar/flutter/RadarFlutterPlugin.java @@ -1312,23 +1312,23 @@ public void run() { Log.e(TAG, e.toString()); } } - - public void onClientLocationUpdated(Context context, Location location, boolean stopped, Radar.RadarLocationSource source) { + @Override + public void onLocationUpdated(Context context, Location location, RadarUser user) { try { SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); - long callbackHandle = sharedPrefs.getLong("clientLocation", 0L); + long callbackHandle = sharedPrefs.getLong("location", 0L); if (callbackHandle == 0L) { + Log.e(TAG, "callback handle is empty"); return; } RadarFlutterPlugin.initializeBackgroundEngine(context); - + JSONObject obj = new JSONObject(); obj.put("location", Radar.jsonForLocation(location)); - obj.put("stopped", stopped); - obj.put("source", source.toString()); + obj.put("user", user.toJson()); HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); synchronized(lock) { @@ -1347,11 +1347,11 @@ public void run() { } } - @Override - public void onError(Context context, Radar.RadarStatus status) { + + public void onClientLocationUpdated(Context context, Location location, boolean stopped, Radar.RadarLocationSource source) { try { SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); - long callbackHandle = sharedPrefs.getLong("error", 0L); + long callbackHandle = sharedPrefs.getLong("clientLocation", 0L); if (callbackHandle == 0L) { return; @@ -1360,7 +1360,9 @@ public void onError(Context context, Radar.RadarStatus status) { RadarFlutterPlugin.initializeBackgroundEngine(context); JSONObject obj = new JSONObject(); - obj.put("status", status.toString()); + obj.put("location", Radar.jsonForLocation(location)); + obj.put("stopped", stopped); + obj.put("source", source.toString()); HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); synchronized(lock) { @@ -1380,10 +1382,10 @@ public void run() { } @Override - public void onLog(Context context, String message) { + public void onError(Context context, Radar.RadarStatus status) { try { SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); - long callbackHandle = sharedPrefs.getLong("log", 0L); + long callbackHandle = sharedPrefs.getLong("error", 0L); if (callbackHandle == 0L) { return; @@ -1392,7 +1394,7 @@ public void onLog(Context context, String message) { RadarFlutterPlugin.initializeBackgroundEngine(context); JSONObject obj = new JSONObject(); - obj.put("message", message); + obj.put("status", status.toString()); HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); synchronized(lock) { @@ -1410,12 +1412,12 @@ public void run() { Log.e(TAG, e.toString()); } } - - @Override - public void onLocationPermissionStatusUpdated(Context context, RadarLocationPermissionStatus status) { + + @Override + public void onLog(Context context, String message) { try { SharedPreferences sharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); - long callbackHandle = sharedPrefs.getLong("locationPermissionStatus", 0L); + long callbackHandle = sharedPrefs.getLong("log", 0L); if (callbackHandle == 0L) { return; @@ -1423,8 +1425,9 @@ public void onLocationPermissionStatusUpdated(Context context, RadarLocationPerm RadarFlutterPlugin.initializeBackgroundEngine(context); - JSONObject obj = status.toJson(); - + JSONObject obj = new JSONObject(); + obj.put("message", message); + HashMap res = new Gson().fromJson(obj.toString(), HashMap.class); synchronized(lock) { final ArrayList args = new ArrayList(); @@ -1441,9 +1444,8 @@ public void run() { Log.e(TAG, e.toString()); } } - } - + public static class RadarFlutterVerifiedReceiver extends RadarVerifiedReceiver { @Override diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 59d7f02..aa55010 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -49,7 +49,7 @@ android { } dependencies { - implementation 'io.radar:sdk:3.14.0' + implementation 'io.radar:sdk:3.15.0' implementation "com.google.android.play:integrity:1.2.0" } } diff --git a/ios/flutter_radar.podspec b/ios/flutter_radar.podspec index f9173c3..9749451 100644 --- a/ios/flutter_radar.podspec +++ b/ios/flutter_radar.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'RadarSDK', '3.14.0' + s.dependency 'RadarSDK', '3.15.0' s.platform = :ios, '10.0' s.static_framework = true From e8ce64e45f03c6fcddea41a2817f433c7dde1d6b Mon Sep 17 00:00:00 2001 From: Kenny Hu Date: Tue, 16 Jul 2024 12:17:07 -0400 Subject: [PATCH 5/6] remove xplatform listeners --- lib/flutter_radar.dart | 43 ------------------------------------------ 1 file changed, 43 deletions(-) diff --git a/lib/flutter_radar.dart b/lib/flutter_radar.dart index e33c7aa..77c43f0 100644 --- a/lib/flutter_radar.dart +++ b/lib/flutter_radar.dart @@ -498,30 +498,6 @@ class Radar { } } - static Future requestBackgroundLocationPermission() async { - try { - await _channel.invokeMethod('requestBackgroundLocationPermission'); - } on PlatformException catch (e) { - print(e); - } - } - - static Future openAppSettings() async { - try { - await _channel.invokeMethod('openAppSettings'); - } on PlatformException catch (e) { - print(e); - } - } - - static Future getLocationPermissionStatus() async { - try { - return await _channel.invokeMethod('getLocationPermissionStatus'); - } on PlatformException catch (e) { - print(e); - return {'error': e.code}; - } - } static onLocation(Function(Map res) callback) async { try { @@ -639,25 +615,6 @@ class Radar { } } - static onLocationPermissionStatus(Function(Map res) callback) async { - try { - final CallbackHandle handle = - PluginUtilities.getCallbackHandle(callback)!; - await _channel.invokeMethod( - 'on', {'listener': 'locationPermissionStatus', 'callbackHandle': handle.toRawHandle()}); - } on PlatformException catch (e) { - print(e); - } - } - - static offLocationPermissionStatus() async { - try { - await _channel.invokeMethod('off', {'listener': 'locationPermissionStatus'}); - } on PlatformException catch (e) { - print(e); - } - } - static Map presetContinuousIOS = { "desiredStoppedUpdateInterval": 30, "desiredMovingUpdateInterval": 30, From b36f7123b3d99b11a3561343ef22c5a7b939d857 Mon Sep 17 00:00:00 2001 From: Kenny Hu Date: Tue, 16 Jul 2024 13:02:15 -0400 Subject: [PATCH 6/6] add to example and fix ios delegate --- example/lib/main.dart | 32 ++++++++++++++++++++++++++++++-- ios/Classes/RadarFlutterPlugin.m | 4 ++-- lib/flutter_radar.dart | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 61bb9b7..8dd34d8 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -249,7 +249,35 @@ class _MyAppState extends State with WidgetsBindingObserver { ); print("searchPlaces: $resp"); }, - child: Text('searchPlaces'), + child: Text('searchPlaces()'), + ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () async { + var resp = await Radar.searchGeofences( + near: { + 'latitude': 40.783826, + 'longitude': -73.975363, + }, + radius: 1000, + limit: 10, + includeGeometry: true, + tags: List.empty(), + metadata: {}, + ); + print("searchGeofences: $resp"); + }, + child: Text('searchGeofences()'), + ), + ElevatedButton( + style: raisedButtonStyle, + onPressed: () async { + var resp = await Radar.geocode( + '20 jay st brooklyn', + ); + print("geocode: $resp"); + }, + child: Text('geocode()'), ), ElevatedButton( style: raisedButtonStyle, @@ -383,7 +411,7 @@ class _MyAppState extends State with WidgetsBindingObserver { Map? resp = await Radar.trackVerified(); print("trackVerified: $resp"); }, - child: Text('trackVerified'), + child: Text('trackVerified()'), ), ElevatedButton( diff --git a/ios/Classes/RadarFlutterPlugin.m b/ios/Classes/RadarFlutterPlugin.m index 16dfa22..33785e3 100644 --- a/ios/Classes/RadarFlutterPlugin.m +++ b/ios/Classes/RadarFlutterPlugin.m @@ -1087,8 +1087,8 @@ - (void)didLogMessage:(NSString *)message { [self.backgroundChannel invokeMethod:@"" arguments:args]; } -- (void)didUpdateToken:(NSString *)token { - NSDictionary *dict = @{@"token": token}; +- (void)didUpdateToken:(RadarVerifiedLocationToken *)token { + NSDictionary *dict = [token dictionaryValue]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSNumber* callbackHandle = [userDefaults objectForKey:@"token"]; if (callbackHandle == 0) { diff --git a/lib/flutter_radar.dart b/lib/flutter_radar.dart index 77c43f0..c6033fa 100644 --- a/lib/flutter_radar.dart +++ b/lib/flutter_radar.dart @@ -469,7 +469,7 @@ class Radar { static Future trackVerified({bool? beacons}) async { try { - return await _channel.invokeMethod('trackVerified', {'beacons': beacons}); + return await _channel.invokeMethod('trackVerified', {'beacons': beacons != null ? beacons : false}); } on PlatformException catch (e) { print(e); return {'error': e.code};