更新唯一标示符

来源:互联网 发布:如何优化供应商 编辑:程序博客网 时间:2024/05/20 02:24
NSMutableDictionary *dictForQuery = [[NSMutableDictionary alloc] init];        [dictForQuery setValue:(id)kSecClassGenericPassword forKey:(id)kSecClass];        NSData *keychainItemID = [NSData dataWithBytes:kKeychainUDIDItemIdentifier                                            length:strlen(kKeychainUDIDItemIdentifier)];    [dictForQuery setValue:keychainItemID forKey:(id)kSecAttrGeneric];    [dictForQuery setValue:(id)kCFBooleanTrue forKey:(id)kSecMatchCaseInsensitive];    [dictForQuery setValue:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];    [dictForQuery setValue:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];        NSDictionary *queryResult = nil;    SecItemCopyMatching((CFDictionaryRef)dictForQuery, (CFTypeRef*)&queryResult);    if (queryResult) {                NSMutableDictionary *dictForUpdate = [[NSMutableDictionary alloc] init];        [dictForUpdate setValue:[NSString stringWithUTF8String:kKeychainUDIDItemIdentifier] forKey:kSecAttrDescription];        [dictForUpdate setValue:keychainItemID forKey:(id)kSecAttrGeneric];                const char *udidStr = [newUDID UTF8String];        NSData *keyChainItemValue = [NSData dataWithBytes:udidStr length:strlen(udidStr)];        [dictForUpdate setValue:keyChainItemValue forKey:(id)kSecValueData];                OSStatus updateErr = noErr;                // First we need the attributes from the Keychain.        NSMutableDictionary *updateItem = [NSMutableDictionary dictionaryWithDictionary:queryResult];                // Second we need to add the appropriate search key/values.        // set kSecClass is Very important        [updateItem setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];                updateErr = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)dictForUpdate);        if (updateErr != errSecSuccess) {            NSLog(@"Update KeyChain Item Error!!! Error Code:%d", (int)updateErr);                        [dictForQuery release];            [dictForUpdate release];            return NO;        }        else {            NSLog(@"Update KeyChain Item Success!!!");            [dictForQuery release];            [dictForUpdate release];            return YES;        }    }        [dictForQuery release];    return NO;

0 0
原创粉丝点击