Skip to main content

Location

TrustFactor uses your location to calculate operations risk. You can set the location manually or allow the SDK to do it for you.

info

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.

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()

Manually

// 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

}
}