iOS---[UIDevice identifierForVendor]慎用!

戚衡
2023-12-01

An alphanumeric string that uniquely identifies a device to the app’s vendor. (read-only)

用于唯一标示设备的字母数字字符串,每一个供应商都不同呀


Declaration

OBJECTIVE-C

@property(nonatomic, readonly, strong) NSUUID *identifierForVendor

Discussion

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.

对于运行于同一个设备,并且来自同一个供应商的所有App,这个值都是相同的。对于一个设备上来自不同供应商的app,这个值不同;不同设备的app,无论供应商相同与否,这个值都不同。


If the value is nil, wait and get the value again later. This happens, for example, after the device has been restarted but before the user has unlocked the device.

如果此值为空,等一会再去获取。用户锁定设备后,再重启设备,此时获取为空,需要解锁。

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. 

当在设备上安装来自同一个供应商的不同App时,此值保持不变。如果你删除了来自某个供应商的所有app,再重新安装时,此值会改变。


请注意,这个属性只能在iOS6之后使用!


我使用iOS10.1.1测试,通过方法“

[[UIDevice currentDevice] identifierForVendor].UUIDString

”获取UUID,每次删除App后,重新获取的新值都不同的。

目前解决方法:获取一次后,使用钥匙串保存起来,这样即使你删除了App,再重新安装,只有BundleId不变,那么从钥匙串中获取的UUID不会变的。

 类似资料: