想要追踪、统计用户,自然离不开用户唯一标识符,这是每个公司都面临的问题。在历史上唯一标识符很多,如UDID、MAC地址、OpenUDID等,有些已经挂掉了.本文介绍几个能用的.
在iOS 6中介绍的Vendor(idfv)或Advertising(idfa)标示符(苹果推荐使用的)
idfa(Advertising Identifier):可以理解为广告id,apple公司提供的用于追踪用户的广告标识符。
缺点:用户可通过设置-隐私-广告-还原广告标识符 还原,之后会得新的到标识符;
要求iOS>=6.0。
使用:#import <AdSupport/AdSupport.h>
NSString *idfa= [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
idfv (identifierForVendor):apple提供给Vendor的唯一标识符,Vendor代表了应用开发商,实际使用时,一个Vendor是CFBundleIdentifier(反转DNS格式)的前两部分。例如,com.baidu.tieba 和 com.baidu.image 得到的idfv是相同的,因为它们的CFBundleIdentifier 前两部分是相同的。
缺点:把同一个开发商的所有应用卸载后,再次安装取到的idfv会不同。
要求:iOS>=6.0
使用:
NSString * idfv =[[UIDevice currentDevice].identifierForVendor UUIDString];
iOS7以后苹果对于sysctl和ioctl进行了技术处理,MAC地址返回的都是02:00:00:00:00:00。官方文档上这样写的“Twolow-level networking APIs that used to return a MAC address now return thefixed value 02:00:00:00:00:00. The APIs in question are sysctl(NET_RT_IFLIST) and ioctl(SIOCGIFCONF). Developers using the value of the MAC address should migrate toidentifiers such as -[UIDevice identifierForVendor].This change affects all apps running on iOS 7”。
所以在iOS7以后想要获取设备的唯一标示Mac地址已经不行了,只能用其他的代替。