Thursday, February 29, 2024
HomeiOS Developmentswift - Uniquely determine an iOS machine

swift – Uniquely determine an iOS machine


I need to get a singular id from an iOS machine even when the consumer deletes the app after which reinstalls. For this I already tried:

let vendorID = UIDevice.present.identifierForVendor?.uuidString
let adIdentifier = ASIdentifierManager.shared().advertisingIdentifier.uuidString

and each return a special quantity once I delete the app then reinstall it.

Then I attempted one other method by writing to the keychain and skim once more from it:

// KeychainService.swift

import Basis
import Safety

class KeychainService {
    
    static let serviceIdentifier = "YourAppIdentifier"
    
    class func saveUUID(_ uuid: String) -> Bool {
        guard let knowledge = uuid.knowledge(utilizing: .utf8) else { return false }
        
        let question: [String: Any] = [
            kSecClass as String: kSecClassGenericPassword,
            kSecAttrService as String: serviceIdentifier,
            kSecValueData as String: data
        ]
        
        SecItemDelete(question as CFDictionary)
        
        let standing = SecItemAdd(question as CFDictionary, nil)
        return standing == errSecSuccess
    }
    
    class func loadUUID() -> String? {
        let question: [String: Any] = [
            kSecClass as String: kSecClassGenericPassword,
            kSecAttrService as String: serviceIdentifier,
            kSecReturnData as String: kCFBooleanTrue!,
            kSecMatchLimit as String: kSecMatchLimitOne
        ]
        
        var outcome: AnyObject?
        let standing = SecItemCopyMatching(question as CFDictionary, &outcome)
        
        if standing == errSecSuccess, let knowledge = outcome as? Knowledge, let uuid = String(knowledge: knowledge, encoding: .utf8) {
            return uuid
        } else {
            return nil
        }
    }
}

/// UUIDModule.swift

import Basis
import React

@objc(UUIDModule)
class UUIDModule: NSObject, RCTBridgeModule {
  
    static func moduleName() -> String {
        return "UUIDModule"
    }

    @objc func getUUID(_ uuid: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
         if let storedUUID = KeychainService.loadUUID() {
            resolve([storedUUID])
        } else {
             let newUUID = UUID().uuidString
             if KeychainService.saveUUID(newUUID) {
                resolve([newUUID])
            } else {
                reject("KeychainError", "Failed to save lots of UUID in keychain", nil)
            }
        }
    }
}

This resolution doesn’t work both.

Any thought how you can clear up this?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments