iOS

The MaxMind Device SDK for iOS is currently in beta.

The MaxMind Device SDK for iOS collects device data and sends it to MaxMind so that the minFraud service can assign a Device ID and use it to detect fraud across sessions. The SDK exposes both a Swift API and an Objective-C API; Objective-C classes use an MM prefix.

Requirements

  • iOS 15.0+
  • Swift 5.9+
  • Xcode 15.0+

Installation

Add the MaxMind Device SDK as a Swift Package dependency. In Xcode, choose File > Add Package Dependencies… and enter the repository URL https://github.com/maxmind/device-ios.git.

Or add it to your Package.swift:

1dependencies: [
2    // Check https://github.com/maxmind/device-ios/releases for the latest version.
3    .package(url: "https://github.com/maxmind/device-ios.git", from: "0.1.0")
4]

Check the device-ios releases for the latest version.

Initialization

Initialize the SDK with your MaxMind account ID. Replace MAXMIND_ACCOUNT_ID with your account ID.

1import MinFraudDevice
2
3let config = SDKConfig(accountID: MAXMIND_ACCOUNT_ID)
4let tracker = DeviceTracker(config: config)
1@import MinFraudDevice;
2
3MMSDKConfig *config = [[MMSDKConfig alloc] initWithAccountID:MAXMIND_ACCOUNT_ID];
4MMDeviceTracker *tracker = [[MMDeviceTracker alloc] initWithConfig:config];

Collect and send device data

Call collectAndSend() to collect device data and send it to MaxMind. The Swift API uses Swift concurrency (async/await); the Objective-C API uses a completion handler.

1import MinFraudDevice
2
3do {
4    let result = try await tracker.collectAndSend()
5    print("Device data sent successfully")
6} catch {
7    print("Failed to send device data: \(error)")
8}
1[tracker collectAndSendWithCompletion:^(MMTrackingResult *result, NSError *error) {
2    if (error) {
3        NSLog(@"Failed to send device data: %@", error);
4        return;
5    }
6    NSLog(@"Device data sent successfully");
7}];

Explicit device linking examples

Capture the trackingToken from the collectAndSend() result and pass it to your backend for inclusion in the minFraud API request.

 1import MinFraudDevice
 2
 3do {
 4    let result = try await tracker.collectAndSend()
 5    let token = result.trackingToken
 6    // Send the tracking token to your backend
 7    sendTokenToBackend(token)
 8} catch {
 9    print("Failed to send device data: \(error)")
10}
1[tracker collectAndSendWithCompletion:^(MMTrackingResult *result, NSError *error) {
2    if (error) {
3        NSLog(@"Failed to send device data: %@", error);
4        return;
5    }
6    // Send the tracking token to your backend
7    [self sendTokenToBackend:result.trackingToken];
8}];

On your backend, include the token in the minFraud API request:

1{
2  "device": {
3    "ip_address": "2001:db8::ff00:42:8329",
4    "tracking_token": "token-value-from-client"
5  }
6}

For full SDK documentation, see the device-ios README.