Associate profile
To associate new profiles you can either use a Deeplink or scan a QR Code.
An association code may require the user to share a precise location with the enrollment — see Precise location below.
Client requirements
Using link
- iOS (Swift)
- Android (Java)
let url = URL(string: "https://....")
trustfactorClient.associateApplicationProfile(using: .deeplink(url)) { result, correlationId in
switch result {
case .success(let associationResult):
// handle result
case .failure(let error):
// handle errors
}
}
Uri uri = Uri.parse("https://....");
trustfactorClient.associateApplicationProfile(uri, (result) -> result.fold(
(TFProfileAssociationResult associationResult, String correlationId) -> {
// handle success
},
(Error error, String correlationId) -> {
// handle errors
}
));
Using an association code
- iOS (Swift)
- Android (Java)
let code = "....."
trustfactorClient.associateApplicationProfile(using: .code(code)) { result, correlationId in
switch result {
case .success(let associationResult):
// value is a boolean we can ignore
case .failure(let error):
// handle errors
}
}
String code = "<>";
trustfactorClient.associateApplicationProfile(code, (result) -> result.fold(
(TFProfileAssociationResult associationResult, String correlationId) -> {
// handle success
},
(Error error, String correlationId) -> {
// handle errors
}
));
Precise location
An application can require a precise location per registration code, so the same application may require it for some enrollments and not for others. Read the requirement from Association details before you start, or simply pass a fix whenever your application holds one — TrustFactor ignores it when the code does not ask for one.
The fix has to be taken for this association. The position shared through
updateLocation(_:) is the device's last known location, is kept without expiry and
may not have come from GPS, so it never satisfies the requirement.
TrustFactor consumes a registration code before it refuses the registration, so an association sent without the location it requires needs a fresh code to retry.
The SDK answers this locally whenever it can: if the code requires a location and none is usable, the association
fails with profileAction(.preciseLocationRequired) before the request leaves the device and the code stays
usable. The same error is returned when TrustFactor refuses the registration itself (E_400100004).
- iOS (Swift)
- Android (Java)
// A location the app captured for this enrollment — CLLocationManager.requestLocation(), not a cached one.
let location: CLLocation = ...
trustfactorClient.associateApplicationProfile(using: .code(code), preciseLocation: location) { result, correlationId in
switch result {
case .success(let associationResult):
// handle result
case .failure(let error):
if let error = error as? TrustFactorError,
error.domain == .profileAction(code: .preciseLocationRequired) {
// ask the user to allow precise location, then retry with the same code
}
// handle errors
}
}
If your app declares NSLocationDefaultAccuracyReduced, a user who granted location access still gives you a
fuzzed position. Call
requestTemporaryFullAccuracyAuthorization(withPurposeKey:)
before capturing the fix, and declare the purpose key in NSLocationTemporaryUsageDescriptionDictionary.
// A location the app captured for this enrollment — not the last known one.
Location location = ...;
trustfactorClient.associateApplicationProfile(code, location, (result) -> result.fold(
(TFProfileAssociationResult associationResult, String correlationId) -> {
// handle success
},
(Error error, String correlationId) -> {
if (error.getDomainCode() == ProfileActionDomainCode.PRECISE_LOCATION_REQUIRED) {
// ask the user to allow precise location, then retry with the same code
}
// handle errors
}
));
Capturing the fix requires ACCESS_FINE_LOCATION. On Android 12+ (API 31) the user may grant only approximate
location even when the app asks for precise — a fuzzed position does not satisfy the requirement, so handle that
case as a refusal and guide the user to the permission settings.