Device ID

参考文章

 

一、CFUUID (Deprecated)

二、UDID (Deprecated)

三、NSUUID (ios6.0 and later)

NSString *uuid = [[NSUUID UUID] UUIDString];

  1) 每次调用都会返回不同的值。

 

四、Advertiser Identifier (ios6.0 and later)

NSString *adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

  1) 需要 AdSupport.framework

  2) 除了以下情况会重新产生新的 id外,一般情况下是固定不变的。

    a> reset the system (Settings.app -> General -> Reset -> Reset All Content and Settings)

    b> 如果用户在 settings 选择了 "Limit Ad Tracking" on,会限制程序访问 Advertiser Identifier。

 

五、Identifier for vendor (ios6.0 and later)

NSString *idfv = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

  1) 在同一个设备上,同 vendor 的 app 的此 id 是一样的。

  2) vendor is defined by the first two parts of the reverse DNS formatted CFBundleIdentifier. 

    example 

      com.doubleencore.app1 and com.doubleencore.app2    same

      com.massivelyoverrated or even net.doubleencore   different

  3) 如果用户把设备上 同一个 vendor 的 apps 都删除掉,下一次安装后此 id 会重新产生。

 

六、第三方的 OpenUDID(ios5.0 and later,不建议使用)

NSString *openUDID = [OpenUDID value];

 

  七、把 device id 存放到 system keychain,只有当设备 system restore 才会重置,而且keychain里保存的信息不会因App被删除而丢失。

    (apple demo “GenericKeychain”)

    1) 下载 apple 提供的 KeychainItemWrapper (如果使用的是 arc ,则需要标示 -fno-objc-arc)

    2)需要的框架:Security.framework

    3)使用

KeychainItemWrapper* keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:bundleID
                                                                            accessGroup:nil];
// 读取
NSString* uuidStr = [keychainItem objectForKey: (id)kSecValueData];

// 写入
[keychainItem setObject:uuidStr forKey:(__bridge id)kSecAttrService];
[keychainItem setObject:uuidStr forKey:(id)kSecValueData];

  

转载于:https://www.cnblogs.com/eileenleung/p/3512937.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值