Location
TrustFactor uses your location to calculate operations risk. You can set the location manually or allow the SDK to do it for you.
Location information can be updated in the background even if the user is not authenticated
Client requirements
Automatic
When using automatic make sure the user gives location permissions. On iOS, if you don't stop the location monitoring the operating system might wake up the app in the background to update the location. You need to handle this on your AppDelegate and update TrustFactor manually.
On Android, location updates are only delivered while the app is in the foreground unless ACCESS_BACKGROUND_LOCATION is also granted. On Android 11+ this permission must be requested separately — the user is taken to system settings to grant it. If background updates are not needed, foreground-only permissions are sufficient.
- iOS (Swift)
- Android (Java)
If your application does not need an accurate location consider Indicating whether the app requests reduced location accuracy by default.
// Start location monitoring
trustFactorClient.startMonitoringLocation()
// Stop location monitoring
trustFactorClient.stopMonitoringLocation()
On Android 12+ (API 31), the user may grant only approximate location even if the app requests precise. startMonitoringLocation() requires ACCESS_FINE_LOCATION — make sure your app handles the case where only approximate location is granted gracefully.
// Start location monitoring
// Requires ACCESS_FINE_LOCATION permission
trustFactorClient.startMonitoringLocation();
// Stop location monitoring
trustFactorClient.stopMonitoringLocation();
Manually
- iOS (Swift)
- Android (Java)
// Use .ip if you have no access to the user location
let provider = .ip
// Use .coreLocation if available
let provider = .coreLocation(<CLLOcation>)
trustFactorClient.updateLocation(provider) { result in
switch result {
case .success(let state):
switch state {
case .updated:
break;
case .notSignificant:
print("Not a significant location change since last update")
}
case .failure(let error):
// handle error
}
}
// Use IP if you have no access to the user location
TFLocation location = new TFLocation(TFLocationProvider.IP);
// Use PRECISE if access is allowed
TFLocation location = new TFLocation(TFLocationProvider.PRECISE, androidLocation);
trustFactorClient.updateLocation(location, (result) -> result.fold(
(TFSetLocationResponse response, String correlationId) -> {
// handle success
},
(Error error, String correlationId) -> {
// handle error
}
));