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 · Jun 3, 2016 · 6599 views
    This topic created in 3805 days ago, the information mentioned may be changed or developed.
    使用简单,就一行代码;轻量级,就一个类文件。
    主要原理是采用 Keychain 来保存 IDFV ,能够保证在 App 被卸载、重装、 iOS 系统升级等一系列情况下设备的 UDID 不会发生改变。会保持持续更新,欢迎提issue...
    附上地址: https://github.com/mushank/ZKUDIDManager

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

    我之前做智能硬件 app 的时候也在研究唯一标识符
    最终结果还是由硬件告诉我他的 mac 地址来确定唯一
    mokaiZz
    mokaiZz
    Jun 4, 2016 via iPhone❤️1
    11
    为什么要 IDFA 呢,随机生成一个 uuid 就行了呀
    mushank
    mushank
    OP
    Jun 4, 2016 via iPhone
    12
    @loveuqian 你说的是 IDFA ,我用的是 IDFV ,你可以查看一下两者的区别。
    mushank
    mushank
    OP
    Jun 4, 2016
    13
    @loveuqian 另外苹果关闭了获取 iOS 设备的 UDID 接口和获取 WIFI 模块 Mac 地址的接口,所以目前而言采用 keychain 保存 IDFV 可能是最好的解决方案了。
    mushank
    mushank
    OP
    Jun 4, 2016
    14
    @mokaiZz 随机生成一个也是可以的,只要能确保其唯一性。另外要做的就是保证你随机生成的 UDID 在各种复杂情况下不会丢失或被重置。
    564425833
    564425833
    Jun 4, 2016 via iPhone
    15
    感谢分享
    daniellu
    daniellu
    Jun 4, 2016
    16
    为什么不用 identifierForVender 呢?这个不是更好么?可以保证同 vender 是绝对一样的(模拟器不可测试)
    mokaiZz
    mokaiZz
    Jun 4, 2016 via iPhone
    17
    @mushank 嗯的
    mushank
    mushank
    OP
    Jun 4, 2016 via iPhone
    18
    @daniellu 该厂商所有 App 都被卸载后, IDFV 是会改变得,所以进一步采用 keychain 确保其前后一致。
    fhefh
    fhefh
    Jun 5, 2016
    19
    mark~~
    iyeatse
    iyeatse
    Jun 5, 2016
    20
    提交了个 PR = =
    mushank
    mushank
    OP
    Jun 5, 2016
    21
    @iyeatse 恩看到啦,非常感谢!
    PhanKiap
    PhanKiap
    Jun 7, 2016
    22
    不开 keychain 同步怎么办?
    mushank
    mushank
    OP
    Jun 7, 2016
    23
    @Dashit 即使不开 iCloud 同步, App 被卸载 /重装 /iOS 系统升级之后、 UDID 也依旧在的。
    PhanKiap
    PhanKiap
    Jun 8, 2016
    24
    @mushank 你这个不是用的 IDFV 吗? UDID 只能通过特殊方法获取吧。
    mushank
    mushank
    OP
    Jun 8, 2016
    25
    @Dashit 恩,这个是用 IDFV 实现 UDID 的功能。。。
    vincentxue
    vincentxue
    Jun 8, 2016 via iPhone
    26
    楼主为什么要重复造轮子… https://github.com/fabiocaccamo/FCUUID
    mushank
    mushank
    OP
    Jun 9, 2016 via iPhone
    27
    @vincentxue 自我觉得自己这个更简简洁易用。。。
    daniellu
    daniellu
    Jun 17, 2016
    28
    @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
    mushank
    OP
    Jun 27, 2016
    29
    @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."
    苹果官方文档,小伙子看文档要看完整。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3534 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 04:17 · PVG 12:17 · LAX 20:17 · JFK 23:17
    ♥ Do have faith in what you're doing.