美文网首页
ios 设备唯一标示

ios 设备唯一标示

作者: fulen | 来源:发表于2017-10-11 10:47 被阅读30次

    1.1很多时候,我们需要拿到手机唯一识别号来进行网络请求处理风控,下面介绍一个拿到手机唯一识别号的方法

    1.1.2 首先将三方库SAMKeychain导入到项目中,然后新建工具类,提供一个类方法

    + (NSString *) generateUUID {
        NSString *uuid = [WXTool getDeviceId];
        if (![NSString isNullOrEmpty:uuid]) {
            return uuid;
        }
        
        NSError *error;
        SAMKeychainQuery *query = [[SAMKeychainQuery alloc] init];
        uuid = [[NSUUID UUID] UUIDString];
        // New item
        query = [[SAMKeychainQuery alloc] init];
        query.password = uuid;
        query.service = kSSKeychainServiceName;
        query.account = kSSKeychainAccountName;
        query.label = kSSKeychainLabel;
        
        if (![query save:&error]) {
            DLog(@"Unable to save item: %@", error);
        }
        return uuid;
    }
    
    + (NSString *)getDeviceId {
        NSError *error;
        // Look up
        SAMKeychainQuery *query = [[SAMKeychainQuery alloc] init];
        query.service = kSSKeychainServiceName;
        query.account = kSSKeychainAccountName;
        query.password = nil;
        
        [query fetch:&error];
        if (error) {
            DLog(@"Network -- Unable to fetch keychain item: %@", error);
        }
        NSString *password = query.password;
        if ([NSString isNullOrEmpty:password]) {
            password = @"";
        }
        return password;
    }
    
    

    相关文章

      网友评论

          本文标题:ios 设备唯一标示

          本文链接:https://www.haomeiwen.com/subject/sgiiyxtx.html