Swiftpack.co - fingerprintjs/fingerprintjs-ios as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by fingerprintjs.
fingerprintjs/fingerprintjs-ios 1.1.2
iOS library for device fingerprinting. Does not require server APIs to work, fully client-side operation.
⭐️ 40
🕓 3 weeks ago
iOS tvOS
.package(url: "https://github.com/fingerprintjs/fingerprintjs-ios.git", from: "1.1.2")

FingerprintJS

Lightweight iOS library for local device fingerprinting

Supported platforms Pod version

Discord server

Demo application on the App Store

Download on the App Store

Installation (CocoaPods)

# Podfile
pod 'FingerprintJS'

Note: If you've never used CocoaPods for dependency management, check out their Using CocoaPods guide that will walk you through the setup process.

Quick Start (async/await - preferred)

import FingerprintJS
 
let fingerprinter = FingerprinterFactory.getInstance()
async {
    // Get fingerprint for the current device
    let fingerprint = await fingerprinter.getFingerprint()
    
    // Do something awesome with the fingerprint
}

Quick Start (closures - backwards compatibility)

import FingerprintJS 

let fingerprinter = FingerprinterFactory.getInstance()
fingerprinter.getFingerprint { fingerprint in
    // Do something awesome with the fingerprint
}

Fingerprint vs. DeviceId

FingerprintJS provides two main methods that return different kinds of identifiers:

  1. Device identifier retrieved by calling Fingerprinter::getDeviceId() that internally uses the identifierForVendor() method which returns a unique identifier for the current application (tied to the device). FingerprintJS further remembers this identifier in the keychain, making the identifier stable even between app reinstalls.

  2. Fingerprinter::getFingerprint() computes a device fingerprint by gathering device information (hardware, OS, device settings, etc.) and computing a hash value from available items. The fingerprint isn't currently as stable as the Device Identifier because the values might change between OS updates or when the user changes settings used to compute the previous value. Future library versions will provide an API with options to customize the stability of the fingerprint.

Configuration

Fingerprinter instance can be configured through the Configuration structure that provides options to select the fingerprint version or change the algorithm that is used to compute the individual fingerprints.

// note that this example exists only to illustrate the available options
// and that its outcome mirrors the current default configuration

let configuration = Configuration(version: .v1, algorithm: .sha256)
let fingerprinter = FingerprinterFactory.getInstance(config)

// fingerprinter uses version 1 of the fingerprint and SHA256 algorithm

Creating Custom Fingerprinting Function

The default hashing function which computes the fingerprint from the content data is SHA256. The Configuration structure offers a way to inject a custom hashing function by specifying .custom(YourCustomFingerprintFunctionInstance) in the algorithm variable:

class HitchhikersFunction: FingerprintFunction {
    func fingerprint(_ data: Data) -> String {
        return "42"
    }
}

let fingerprintFunction = HitchhikersFunction()
let config = Configuration(version: .v1, algorithm: .custom(fingerprintFunction))
let fingerprinter = FingerprinterFactory.getInstance(config)

let fingerprint = await fingerprinter.getFingerprint() // returns "42"

Keep in mind that the change in the supplied hashing function will inevitably lead to the change of the output fingerprint.

License

This library is MIT licensed. Copyright FingerprintJS, Inc. 2022.

GitHub

link
Stars: 40
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.1.2
3 weeks ago
  • Added support for iOS 12 and tvOS 12
  • Default fingerprint computation uses SHA256 from CommonCrypto on iOS/tvOS 12 and CryptoKit on iOS/tvOS 13 and above.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics