IT박스

기기에서 iOS 앱을 제거한 후 iOS에서 identifierForVendor를 보존하는 방법은 무엇입니까?

itboxs 2020. 11. 18. 08:48
반응형

기기에서 iOS 앱을 제거한 후 iOS에서 identifierForVendor를 보존하는 방법은 무엇입니까?


로그인을 위해 웹 서비스를 호출하는 iOS 앱을 개발 중이며, 이때 공급 업체 식별자 (identifierForVendor)와 함께 로그인 자격 증명을 웹 서버에 보내 해당 자격 증명에 대해 장치를 고유하게 식별합니다. 따라서 사용자는 하나의 장치와 하나의 자격 증명 만 가질 수 있습니다. .

나는 identifierForVendor를 얻었다.

NSString *uuid = [[UIDevice currentDevice] identifierForVendor].UUIDString

이 식별자는 웹 서버의 데이터베이스와 장치 데이터베이스에 저장되며 다음 번에 사용자가 응용 프로그램을 열고 웹 서버에서 데이터를 다운로드하려고 할 때 먼저 사용자 장치의 local identifierForVendor가 웹 서버에 저장된 식별자와 비교합니다.

사용자가 앱을 제거하고 다시 설치할 때 문제가 발생하며 identifierForVendor가 변경된 것을 발견했습니다. 따라서 사용자는 더 이상 진행할 수 없습니다.

사과 문서 UIDevice 문서를 읽었습니다.

거기에서 언급했듯이 동일한 공급 업체의 모든 앱이 장치에서 제거되면 해당 공급 업체의 모든 앱을 새로 설치할 때 새로운 identifierForVendor가 사용됩니다.

제 경우에는 어떻게 처리해야합니까?


KeyChain에 보관할 수 있습니다.

-(NSString *)getUniqueDeviceIdentifierAsString
{

 NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];

 NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
 if (strApplicationUUID == nil)
 {
    strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
 }

 return strApplicationUUID;
}

일반적으로 identifierForVendor. 대신을 사용 NSUUID하여 사용자 지정 UUID를 생성하고 키 체인에 저장합니다 (앱을 삭제하고 다시 설치해도 키 체인은 삭제되지 않기 때문입니다).


@nerowolfe의 답변에 추가 .

SSKeychainkSecAttrSynchronizableAny기본 동기화 모드로 사용 합니다. identifierForVendor여러 장치에서 동기화되고 싶지 않을 수 있으므로 다음 코드가 있습니다.

// save identifierForVendor in keychain without sync
NSError *error = nil;
SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
query.service = @"your_service";
query.account = @"your_account";
query.password = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
query.synchronizationMode = SSKeychainQuerySynchronizationModeNo;
[query save:&error];

앱을 제거하더라도 기기가 재설정 될 때까지 존재하는 VendorIdentifier 를 저장하기 위해 KeyChain사용해 볼 수 있습니다.


확인. SSKeychain이라는 타사를 사용하고 싶지 않았습니다. 그래서 이것은 내가 시도한 코드이며 상당히 간단하며 잘 작동합니다.

    NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];

KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:bundleId accessGroup:nil];
if(![keychainItem objectForKey:(__bridge id)(kSecValueData)]){
    NSString *idfa = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    [keychainItem setObject:idfa forKey:(__bridge id)(kSecValueData)];
    NSLog(@"saving item %@", [keychainItem objectForKey:(__bridge id)(kSecValueData)]);
}else{
    NSLog(@"saved item is %@", [keychainItem objectForKey:(__bridge id)(kSecValueData)]);
}

Swift 버전

func UUID() -> String {

    let bundleName = NSBundle.mainBundle().infoDictionary!["CFBundleName"] as! String
    let accountName = "incoding"

    var applicationUUID = SAMKeychain.passwordForService(bundleName, account: accountName)

    if applicationUUID == nil {

        applicationUUID = UIDevice.currentDevice().identifierForVendor!.UUIDString

        // Save applicationUUID in keychain without synchronization
        let query = SAMKeychainQuery()
        query.service = bundleName
        query.account = accountName
        query.password = applicationUUID
        query.synchronizationMode = SAMKeychainQuerySynchronizationMode.No

        do {
            try query.save()
        } catch let error as NSError {
            print("SAMKeychainQuery Exception: \(error)")
        }
    }

    return applicationUUID
}

더 이상 고유 번호를 장치에 연결하는 명확한 방법이 없으며 Apple 개인 정보 보호 지침에서는 허용되지 않습니다.

키 체인에 자신의 고유 ID를 저장할 수 있지만 사용자가 기기를 지우면이 ID도 사라집니다.

일반적으로 더 이상 사용자를 식별하는 것이 아니라 기기를 식별하기 때문에 기기를 사용자 에게 연결하는 것은 잘못된 것 입니다. 따라서 사용자가 다시 로그인 할 수 있고 공급 업체 ID가 사용자 계정에 바인딩되도록 API를 변경해야합니다.

Also what happens when the user has more then one device, like an iPhone and iPad, and uses you app on both? Since you authentication is based an unique ID this can not be done.


I had used KeychainAccess pod for this problem.

In your pod file :

pod 'KeychainAccess', '~> 2.4' //If you are using Swift 2.3 
pod 'KeychainAccess' //Defaults to 3.0.1 which is in Swift 3

Import KeychainAccess module in file where you want to set UUID in keychain

import KeychainAccess

Use below code to set and get UUID from keychain :

Note : BundleId is key and UUID is value

var bundleID = NSBundle.mainBundle().bundleIdentifier
    var uuidValue = UIDevice.currentDevice().identifierForVendor!.UUIDString

 //MARK: - setVenderId and getVenderId
    func setVenderId() {

        let keychain = Keychain(service: bundleID!)

        do {
            try keychain.set(venderId as String, key: bundleID!)
            print("venderId set : key \(bundleID) and value: \(venderId)")
        }
        catch let error {
            print("Could not save data in Keychain : \(error)")
        }
    }

    func getVenderId() -> String {
        let keychain = Keychain(service: bundleID!)
        let token : String = try! keychain.get(bundleID!)!
        return token
    }

참고URL : https://stackoverflow.com/questions/21878560/how-to-preserve-identifierforvendor-in-ios-after-uninstalling-ios-app-on-device

반응형