V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
mushank
V2EX  ›  iDev

写了一个 iOS 下生成和管理设备唯一标识符( UDID)的组件,分享一下...

  •  
  •   mushank · 2016-06-03 17:02:14 +08:00 · 5351 次点击
    这是一个创建于 2885 天前的主题,其中的信息可能已经有所发展或是发生改变。
    使用简单,就一行代码;轻量级,就一个类文件。
    主要原理是采用 Keychain 来保存 IDFV ,能够保证在 App 被卸载、重装、 iOS 系统升级等一系列情况下设备的 UDID 不会发生改变。会保持持续更新,欢迎提issue...
    附上地址: https://github.com/mushank/ZKUDIDManager

    第一次发帖,好鸡冻...
    29 条回复    2016-06-27 19:40:35 +08:00
    mynameisz
        1
    mynameisz  
       2016-06-03 17:16:33 +08:00
    感谢分享。
    TonyYOYO
        2
    TonyYOYO  
       2016-06-03 18:17:29 +08:00
    IDFV 是啥。。
    Tankpt
        3
    Tankpt  
       2016-06-03 18:38:18 +08:00
    好牛逼
    lizhenda
        5
    lizhenda  
       2016-06-03 19:54:15 +08:00
    这个不错哦~收藏下
    mushank
        6
    mushank  
    OP
       2016-06-03 23:47:05 +08:00
    @mynameisz 嗯嗯,不客气!
    mushank
        7
    mushank  
    OP
       2016-06-03 23:49:10 +08:00
    @TonyYOYO identifierForVendor ,具体解释可以查看一下苹果官方文档,还是很容易理解的,另外 4L 那个博客解释的也很清楚喔。
    mushank
        8
    mushank  
    OP
       2016-06-03 23:51:51 +08:00
    @Tankpt 不好好加班逛什么 V2 !
    mushank
        9
    mushank  
    OP
       2016-06-03 23:57:36 +08:00
    @lizhenda 嗯嗯,已经加入公司实际项目使用过,暂时效果良好,如有问题欢迎提 Issue 或者直接 Pull request 哈!
    loveuqian
        10
    loveuqian  
       2016-06-04 00:10:47 +08:00
    我记得你的项目没有 IDFA 相关的东西是不能使用 IDFA 的?

    我之前做智能硬件 app 的时候也在研究唯一标识符
    最终结果还是由硬件告诉我他的 mac 地址来确定唯一
    mokaiZz
        11
    mokaiZz  
       2016-06-04 00:18:13 +08:00 via iPhone   ❤️ 1
    为什么要 IDFA 呢,随机生成一个 uuid 就行了呀
    mushank
        12
    mushank  
    OP
       2016-06-04 00:38:15 +08:00 via iPhone
    @loveuqian 你说的是 IDFA ,我用的是 IDFV ,你可以查看一下两者的区别。
    mushank
        13
    mushank  
    OP
       2016-06-04 00:46:03 +08:00
    @loveuqian 另外苹果关闭了获取 iOS 设备的 UDID 接口和获取 WIFI 模块 Mac 地址的接口,所以目前而言采用 keychain 保存 IDFV 可能是最好的解决方案了。
    mushank
        14
    mushank  
    OP
       2016-06-04 00:50:25 +08:00
    @mokaiZz 随机生成一个也是可以的,只要能确保其唯一性。另外要做的就是保证你随机生成的 UDID 在各种复杂情况下不会丢失或被重置。
    564425833
        15
    564425833  
       2016-06-04 10:28:35 +08:00 via iPhone
    感谢分享
    daniellu
        16
    daniellu  
       2016-06-04 20:55:23 +08:00
    为什么不用 identifierForVender 呢?这个不是更好么?可以保证同 vender 是绝对一样的(模拟器不可测试)
    mokaiZz
        17
    mokaiZz  
       2016-06-04 21:06:36 +08:00 via iPhone
    @mushank 嗯的
    mushank
        18
    mushank  
    OP
       2016-06-04 23:19:41 +08:00 via iPhone
    @daniellu 该厂商所有 App 都被卸载后, IDFV 是会改变得,所以进一步采用 keychain 确保其前后一致。
    fhefh
        19
    fhefh  
       2016-06-05 13:47:42 +08:00
    mark~~
    iyeatse
        20
    iyeatse  
       2016-06-05 16:48:02 +08:00
    提交了个 PR = =
    mushank
        21
    mushank  
    OP
       2016-06-05 23:25:52 +08:00
    @iyeatse 恩看到啦,非常感谢!
    Dashit
        22
    Dashit  
       2016-06-07 17:46:55 +08:00
    不开 keychain 同步怎么办?
    mushank
        23
    mushank  
    OP
       2016-06-07 22:25:18 +08:00
    @Dashit 即使不开 iCloud 同步, App 被卸载 /重装 /iOS 系统升级之后、 UDID 也依旧在的。
    Dashit
        24
    Dashit  
       2016-06-08 08:41:34 +08:00
    @mushank 你这个不是用的 IDFV 吗? UDID 只能通过特殊方法获取吧。
    mushank
        25
    mushank  
    OP
       2016-06-08 10:11:59 +08:00
    @Dashit 恩,这个是用 IDFV 实现 UDID 的功能。。。
    vincentxue
        26
    vincentxue  
       2016-06-08 21:31:58 +08:00 via iPhone
    楼主为什么要重复造轮子… https://github.com/fabiocaccamo/FCUUID
    mushank
        27
    mushank  
    OP
       2016-06-09 17:22:21 +08:00 via iPhone
    @vincentxue 自我觉得自己这个更简简洁易用。。。
    daniellu
        28
    daniellu  
       2016-06-17 18:12:30 +08:00
    @mushank 刚刚查过了, identifierForVendor 对于同一个厂商来说,是不变的。如果是从 store 下载的, store 会给设定 vendor ,如果是用企业证书分发,是会用 bundle id 判断。这个个人觉得不会出现同一个供应商的程序卸载之后会不同,如果这样的话,也不需要提供这个 API 了。

    唯一需要注意的是,用 bundle id 判断的时候, iOS 6 和 iOS 7+判断部分不同( iOS 6 是前 2 部分, 7+不是)。

    The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

    Normally, the vendor is determined by data provided by the App Store. If the app was not installed from the app store (such as enterprise apps and apps still in development), then a vendor identifier is calculated based on the app ’ s bundle ID. The bundle ID is assumed to be in reverse-DNS format.

    On iOS 6, the first two components of the bundle ID are used to generate the vendor ID. if the bundle ID only has a single component, then the entire bundle ID is used.

    On IOS 7, all components of the bundle except for the last component are used to generate the vendor ID. If the bundle ID only has a single component, then the entire bundle ID is used.
    mushank
        29
    mushank  
    OP
       2016-06-27 19:40:35 +08:00
    @daniellu "The value changes when the user deletes all of that vendor ’ s apps from the device and subsequently reinstalls one or more of them."
    苹果官方文档,小伙子看文档要看完整。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   893 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:01 · PVG 06:01 · LAX 15:01 · JFK 18:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.