每台Apple设备(iPad/iPhone/iPod)在其使用范围内是否只有一个唯一标识符?以下代码是否会始终返回该标识符?唯一设备标识符
[[UIDevice currentDevice] uniqueIdentifier];
Apple允许在部署的应用程序中使用此方法吗?
每台Apple设备(iPad/iPhone/iPod)在其使用范围内是否只有一个唯一标识符?以下代码是否会始终返回该标识符?唯一设备标识符
[[UIDevice currentDevice] uniqueIdentifier];
Apple允许在部署的应用程序中使用此方法吗?
UDID(uniqueidentifier)是终身的,但是,不确定苹果是否很高兴你调用该方法来检索它。
苹果公司日前宣布,2013年5月将开始拒绝使用UDID的应用程序来跟踪用户行为
这是对UDID的替代:
您可以创建UIApplication的,的UIDevice的类别或作为你prefere像这样(ARC例如)
@interface UIApplication (utilities)
- (NSString*)getUUID;
@end
@implementation UIApplication (utilities)
- (NSString*)getUUID {
NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
static NSString *uuid = nil;
// try to get the NSUserDefault identifier if exist
if (uuid == nil) {
uuid = [standardUserDefault objectForKey:@"UniversalUniqueIdentifier"];
}
// if there is not NSUserDefault identifier generate one and store it
if (uuid == nil) {
uuid = UUID();
[standardUserDefault setObject:uuid forKey:@"UniversalUniqueIdentifier"];
[standardUserDefault synchronize];
}
return uuid;
}
@end
UUID()是这个函数
NSString* UUID() {
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return (__bridge NSString *)uuidStringRef;
}
这会生成一个存储在NSUserDefault中的唯一标识符,以便在应用程序需要时重复使用 - 此标识符将与应用程序不相关的唯一相关信息安装到设备上,但可用于例如跟踪订阅APN的设备数量服务等等
之后,你可以这样使用它:
NSString *uuid = [[UIApplication sharedApplication] getUUID];
如果你看一下属性的文件,苹果鼓励如果需要的话,你使用它。 –
所有的问题是,我想建立一个应用程序,让用户免费第一个月,在Web服务的帮助下,我可以确保删除并重新安装该功能不会欺骗应用程序,并获得另一个新的免费月份 – user784625
相关文档是http://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/uniqueIdentifier - 它是官方API和Apple建议它的潜在用途(“您可以将UDID与特定于应用程序的用户ID结合使用,以识别服务器上的特定于应用程序的数据。”)。正如你所说,它也清楚地解释说这件事是独一无二的,并与设备绑定在一起。 – Tommy