我想知道在苹果设备(iPod Touch,iPhone或iPad)上可以使用和存储什么来生成唯一标识符,例如IMEI或其他内容... 我只需要一个唯一的东西,以便我的应用程序可以执行“同一设备一次”的验证。
谢谢。
我想知道在苹果设备(iPod Touch,iPhone或iPad)上可以使用和存储什么来生成唯一标识符,例如IMEI或其他内容... 我只需要一个唯一的东西,以便我的应用程序可以执行“同一设备一次”的验证。
谢谢。
您可以使用NSUUID。但是这个值会改变,因此您可以在应用程序首次打开时调用它并保存它来实现该功能。
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
//App has previously launched
}
else
{
//First launch
NSString *identifierString = [[NSUUID UUID] UUIDString];
[[NSUserDefaults standardUserDefaults] setObject:identifierString forKey:@"uuidKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
编辑:如需更多信息和可用选项,请参阅这篇优秀文章。
如果您使用的是iOS 6.0或更高版本,您可以使用UIDevice
中的identifierForVendor
方法。
NSUUID* pUUID;
UIDevice* pThisDvc;
pThisDvc = [UIDevice currentDevice];
if ( pThisDvc )
{
pUUID = [pThisDvc identifierForVendor];
}
if (pThisDvc)
?? 是否有任何情况 [UIDevice currentDevice]
不返回有效对象? - n00bProgrammerNSUUID* identifier = [[UIDevice currentDevice] identifierForVendor];
NSString* uniqueIdentifier = [identifier UUIDString];
这将返回当前设备的唯一标识符,对于每个应用程序都是唯一的。苹果建议在一般情况下使用此标识符,在广告目的下使用advertisingIdentifier
。
在实现广告服务系统时,请使用ASIdentifierManager类中的
advertisingIdentifier
属性值,而不是使用此属性。使用该属性需要遵循类讨论中为正确使用该标识符设置的指南。有关更多信息,请参见ASIdentifierManager Class Reference。
...来自这里