Skip to content

Commit d8cc7b3

Browse files
committed
feat: add Proximity Detection init options
`allowUseOfLocationData` - to allow collect location data `locationTimeoutMillis` - to configure the location retrieval timeout on Android
1 parent a1a25ff commit d8cc7b3

File tree

10 files changed

+206
-11
lines changed

10 files changed

+206
-11
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,29 @@ void identify() async {
210210
}
211211
```
212212

213+
### Proximity Detection
214+
215+
Proximity detection is a complementary, location-based signal available only on mobile platforms.
216+
More info you can find in [Android SDK documentation](https://dev.fingerprint.com/docs/native-android-integration#/proximity-detection-for-android-devices) or in
217+
[iOS SDK documentation](https://dev.fingerprint.com/docs/ios-sdk#/using-location-data-for-proximity-detection).
218+
219+
The Fingerprint SDK will only collect location data if the `allowUseOfLocationData` option is set to `true`.
220+
221+
```dart
222+
void doInit() async {
223+
await FpjsProPlugin.initFpjs('<PUBLIC_API_KEY>', allowUseOfLocationData: true);
224+
}
225+
```
226+
227+
For Android platform it's possible to configure the location retrieval timeout by setting the `locationTimeoutMillis` option to a desired value. By default, it's set to 5 seconds.
228+
229+
```dart
230+
void doInit() async {
231+
await FpjsProPlugin.initFpjs('<PUBLIC_API_KEY>', allowUseOfLocationData: true,
232+
locationTimeoutMillis: 10000);
233+
}
234+
```
235+
213236
## Additional Resources
214237
- [Fingerprint Pro documentation](https://dev.fingerprint.com/docs)
215238
- [Server API](https://dev.fingerprint.com/reference/server-api)

android/src/main/kotlin/com/fingerprintjs/flutter/fpjs_pro/fpjs_pro_plugin/FpjsProPlugin.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,20 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
6868
val extendedResponseFormat = call.argument<Boolean>("extendedResponseFormat") ?: false
6969
val pluginVersion = call.argument<String>("pluginVersion") ?: "unknown"
7070

71-
initFpjs(token, region, endpoint, endpointFallbacks, extendedResponseFormat, pluginVersion)
71+
val allowUseOfLocationData = call.argument<Boolean>("allowUseOfLocationData") ?: false
72+
73+
val locationTimeoutMillis = call.argument<Int>("locationTimeoutMillis") ?: 5000
74+
75+
initFpjs(
76+
token,
77+
region,
78+
endpoint,
79+
endpointFallbacks,
80+
extendedResponseFormat,
81+
pluginVersion,
82+
allowUseOfLocationData,
83+
locationTimeoutMillis.toLong()
84+
)
7285
result.success("Successfully initialized FingerprintJS Pro Client")
7386
}
7487
GET_VISITOR_ID -> {
@@ -101,15 +114,26 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
101114
channel.setMethodCallHandler(null)
102115
}
103116

104-
private fun initFpjs(apiToken: String, region: Configuration.Region?, endpoint: String?, endpointFallbacks:List<String>?, extendedResponseFormat: Boolean, pluginVersion: String) {
117+
private fun initFpjs(
118+
apiToken: String,
119+
region: Configuration.Region?,
120+
endpoint: String?,
121+
endpointFallbacks: List<String>?,
122+
extendedResponseFormat: Boolean,
123+
pluginVersion: String,
124+
allowUseOfLocationData: Boolean,
125+
locationTimeoutMillis: Long
126+
) {
105127
val factory = FingerprintJSFactory(applicationContext)
106128
val configuration = Configuration(
107129
apiToken,
108130
region ?: Configuration.Region.US,
109131
endpoint ?: region?.endpointUrl ?: Configuration.Region.US.endpointUrl,
110132
extendedResponseFormat,
111133
endpointFallbacks ?: emptyList(),
112-
listOf(Pair("fingerprint-pro-flutter", pluginVersion))
134+
listOf(Pair("fingerprint-pro-flutter", pluginVersion)),
135+
allowUseOfLocationData,
136+
locationTimeoutMillis,
113137
)
114138

115139
fpjsClient = factory.createInstance(configuration)

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.fingerprintjs.flutter.fpjs_pro.fpjs_pro_plugin_example">
3+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
4+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
35
<application
46
android:label="fpjs_pro_plugin_example"
57
android:name="${applicationName}"

example/ios/Podfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ PODS:
44
- fpjs_pro_plugin (3.3.2):
55
- FingerprintPro (< 2.11.0, >= 2.10.0)
66
- Flutter
7+
- geolocator_apple (1.2.0):
8+
- Flutter
9+
- FlutterMacOS
710

811
DEPENDENCIES:
912
- Flutter (from `Flutter`)
1013
- fpjs_pro_plugin (from `.symlinks/plugins/fpjs_pro_plugin/ios`)
14+
- geolocator_apple (from `.symlinks/plugins/geolocator_apple/darwin`)
1115

1216
SPEC REPOS:
1317
trunk:
@@ -18,11 +22,14 @@ EXTERNAL SOURCES:
1822
:path: Flutter
1923
fpjs_pro_plugin:
2024
:path: ".symlinks/plugins/fpjs_pro_plugin/ios"
25+
geolocator_apple:
26+
:path: ".symlinks/plugins/geolocator_apple/darwin"
2127

2228
SPEC CHECKSUMS:
2329
FingerprintPro: f72cfc225731a66d53dd8be3545fbbbd4f4c4777
2430
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
2531
fpjs_pro_plugin: 17d12dddc60fe3d11011e9e98904bc8b30d48a47
32+
geolocator_apple: ab36aa0e8b7d7a2d7639b3b4e48308394e8cef5e
2633

2734
PODFILE CHECKSUM: 2f1a6d2470f392e010cfe7ae5f9f694d8487db82
2835

example/ios/Runner/Info.plist

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>CADisableMinimumFrameDurationOnPhone</key>
6+
<true/>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>$(DEVELOPMENT_LANGUAGE)</string>
79
<key>CFBundleDisplayName</key>
@@ -24,6 +26,8 @@
2426
<string>$(FLUTTER_BUILD_NUMBER)</string>
2527
<key>LSRequiresIPhoneOS</key>
2628
<true/>
29+
<key>UIApplicationSupportsIndirectInputEvents</key>
30+
<true/>
2731
<key>UILaunchStoryboardName</key>
2832
<string>LaunchScreen</string>
2933
<key>UIMainStoryboardFile</key>
@@ -43,9 +47,7 @@
4347
</array>
4448
<key>UIViewControllerBasedStatusBarAppearance</key>
4549
<false/>
46-
<key>CADisableMinimumFrameDurationOnPhone</key>
47-
<true/>
48-
<key>UIApplicationSupportsIndirectInputEvents</key>
49-
<true/>
50+
<key>NSLocationWhenInUseUsageDescription</key>
51+
<string>Activate location for Proximity Detection</string>
5052
</dict>
5153
</plist>

example/lib/main.dart

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
66
import 'package:fpjs_pro_plugin/error.dart';
77
import 'package:fpjs_pro_plugin/fpjs_pro_plugin.dart';
88
import 'package:fpjs_pro_plugin/region.dart';
9+
import 'package:geolocator/geolocator.dart';
910

1011
const tags = {
1112
'a': 'a',
@@ -18,7 +19,7 @@ const tags = {
1819
};
1920

2021
Future main() async {
21-
// Explicitly define which files to load to avoid
22+
// Explicitly define which files to load to avoid
2223
// console warnings about not finding other possible .env files
2324
await dotenv.load(fileNames: ['.env', '.env.local']);
2425
runApp(const MyApp());
@@ -69,6 +70,8 @@ class _MyAppState extends State<MyApp> {
6970
endpoint: _endpoint,
7071
scriptUrlPattern: _scriptUrlPattern,
7172
region: _parseRegion(_region),
73+
allowUseOfLocationData: true,
74+
locationTimeoutMillis: 6000,
7275
extendedResponseFormat: true);
7376
} catch (error) {
7477
// print('Failed to initialize Fingerprint agent: $error');
@@ -78,10 +81,32 @@ class _MyAppState extends State<MyApp> {
7881
}
7982
}
8083

84+
Future<void> requestPermission() async {
85+
LocationPermission permission = await Geolocator.checkPermission();
86+
if (permission == LocationPermission.denied) {
87+
permission = await Geolocator.requestPermission();
88+
if (permission == LocationPermission.denied) {
89+
// Permissions are denied, next time you could try
90+
// requesting permissions again (this is also where
91+
// Android's shouldShowRequestPermissionRationale
92+
// returned true. According to Android guidelines
93+
// your App should show an explanatory UI now.
94+
return Future.error('Location permissions are denied');
95+
}
96+
}
97+
98+
if (permission == LocationPermission.deniedForever) {
99+
// Permissions are denied forever, handle appropriately.
100+
return Future.error(
101+
'Location permissions are permanently denied, we cannot request permissions.');
102+
}
103+
}
104+
81105
/// The native FingerprintJS libraries expose a method called `getVisitorId`
82106
/// to stay consistent with the original Javascript library used for browser identification.
83107
/// However in the mobile application context a more accurate name would be something like `getDeviceId`.
84108
Future<void> _getDeviceId() async {
109+
await requestPermission();
85110
String deviceId;
86111
try {
87112
deviceId = await FpjsProPlugin.getVisitorId(
@@ -102,6 +127,7 @@ class _MyAppState extends State<MyApp> {
102127
}
103128

104129
Future<String> _getDeviceData() async {
130+
await requestPermission();
105131
String identificationInfo;
106132
try {
107133
const encoder = JsonEncoder.withIndent(' ');
@@ -121,6 +147,7 @@ class _MyAppState extends State<MyApp> {
121147
}
122148

123149
Future<void> _runChecks() async {
150+
await requestPermission();
124151
setState(() {
125152
_checksResult = 'Running';
126153
});

example/pubspec.lock

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ packages:
4141
url: "https://pub.dev"
4242
source: hosted
4343
version: "1.19.1"
44+
crypto:
45+
dependency: transitive
46+
description:
47+
name: crypto
48+
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
49+
url: "https://pub.dev"
50+
source: hosted
51+
version: "3.0.6"
4452
cupertino_icons:
4553
dependency: "direct main"
4654
description:
@@ -65,6 +73,14 @@ packages:
6573
url: "https://pub.dev"
6674
source: hosted
6775
version: "1.3.3"
76+
fixnum:
77+
dependency: transitive
78+
description:
79+
name: fixnum
80+
sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be
81+
url: "https://pub.dev"
82+
source: hosted
83+
version: "1.1.1"
6884
flutter:
6985
dependency: "direct main"
7086
description: flutter
@@ -95,6 +111,54 @@ packages:
95111
relative: true
96112
source: path
97113
version: "4.2.0"
114+
geolocator:
115+
dependency: "direct main"
116+
description:
117+
name: geolocator
118+
sha256: f62bcd90459e63210bbf9c35deb6a51c521f992a78de19a1fe5c11704f9530e2
119+
url: "https://pub.dev"
120+
source: hosted
121+
version: "13.0.4"
122+
geolocator_android:
123+
dependency: transitive
124+
description:
125+
name: geolocator_android
126+
sha256: fcb1760a50d7500deca37c9a666785c047139b5f9ee15aa5469fae7dbbe3170d
127+
url: "https://pub.dev"
128+
source: hosted
129+
version: "4.6.2"
130+
geolocator_apple:
131+
dependency: transitive
132+
description:
133+
name: geolocator_apple
134+
sha256: dbdd8789d5aaf14cf69f74d4925ad1336b4433a6efdf2fce91e8955dc921bf22
135+
url: "https://pub.dev"
136+
source: hosted
137+
version: "2.3.13"
138+
geolocator_platform_interface:
139+
dependency: transitive
140+
description:
141+
name: geolocator_platform_interface
142+
sha256: "30cb64f0b9adcc0fb36f628b4ebf4f731a2961a0ebd849f4b56200205056fe67"
143+
url: "https://pub.dev"
144+
source: hosted
145+
version: "4.2.6"
146+
geolocator_web:
147+
dependency: transitive
148+
description:
149+
name: geolocator_web
150+
sha256: b1ae9bdfd90f861fde8fd4f209c37b953d65e92823cb73c7dee1fa021b06f172
151+
url: "https://pub.dev"
152+
source: hosted
153+
version: "4.1.3"
154+
geolocator_windows:
155+
dependency: transitive
156+
description:
157+
name: geolocator_windows
158+
sha256: "175435404d20278ffd220de83c2ca293b73db95eafbdc8131fe8609be1421eb6"
159+
url: "https://pub.dev"
160+
source: hosted
161+
version: "0.2.5"
98162
leak_tracker:
99163
dependency: transitive
100164
description:
@@ -159,6 +223,14 @@ packages:
159223
url: "https://pub.dev"
160224
source: hosted
161225
version: "1.9.1"
226+
plugin_platform_interface:
227+
dependency: transitive
228+
description:
229+
name: plugin_platform_interface
230+
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
231+
url: "https://pub.dev"
232+
source: hosted
233+
version: "2.1.8"
162234
sky_engine:
163235
dependency: transitive
164236
description: flutter
@@ -172,6 +244,14 @@ packages:
172244
url: "https://pub.dev"
173245
source: hosted
174246
version: "1.10.0"
247+
sprintf:
248+
dependency: transitive
249+
description:
250+
name: sprintf
251+
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
252+
url: "https://pub.dev"
253+
source: hosted
254+
version: "7.0.0"
175255
stack_trace:
176256
dependency: transitive
177257
description:
@@ -212,6 +292,22 @@ packages:
212292
url: "https://pub.dev"
213293
source: hosted
214294
version: "0.7.6"
295+
typed_data:
296+
dependency: transitive
297+
description:
298+
name: typed_data
299+
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
300+
url: "https://pub.dev"
301+
source: hosted
302+
version: "1.4.0"
303+
uuid:
304+
dependency: transitive
305+
description:
306+
name: uuid
307+
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
308+
url: "https://pub.dev"
309+
source: hosted
310+
version: "4.5.1"
215311
vector_math:
216312
dependency: transitive
217313
description:
@@ -228,6 +324,14 @@ packages:
228324
url: "https://pub.dev"
229325
source: hosted
230326
version: "14.3.0"
327+
web:
328+
dependency: transitive
329+
description:
330+
name: web
331+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
332+
url: "https://pub.dev"
333+
source: hosted
334+
version: "1.1.1"
231335
sdks:
232336
dart: ">=3.8.0-0 <4.0.0"
233337
flutter: ">=3.18.0-18.0.pre.54"

example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
flutter:
2020
sdk: flutter
2121
env_flutter: ^0.1.4
22+
geolocator: ^13.0.4
2223

2324
fpjs_pro_plugin:
2425
# When depending on this package from a real application you should use:

0 commit comments

Comments
 (0)