我知道[[UIDevice currentDevice] uniqueIdentifier]被拒绝了,我使用:
- (NSString *) uniqueDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier];
NSString *uniqueIdentifier = [stringToHash stringFromMD5];
return uniqueIdentifier;
}如果我的方法没有被苹果批准,我可以用什么方法获得唯一的标识符?
发布于 2013-04-11 13:13:31
这个项目做的事情与您正在做的事情类似:https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5。我相信它现在已经被苹果接受了。实际上,要回答你的问题,没有其他(公共)方法可以获得一个不仅是唯一的,而且对每个应用程序都相同的id。@Vishal的使用方法:
+ (NSString *)GetUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}以及@JeffWolski的使用方法:
[[NSUUID UUID] UUIDString];如果你不需要设备id在不同的应用程序之间保持一致,只需要一种方法来识别你自己的特定设备,那么就可以工作了。如果您需要在应用程序之间工作的设备ID,则需要使用您的代码或开源项目来使用设备MAC地址。
更新
我刚刚找到了另一个解决方案。您可以使用[[UIDevice currentDevice] identifierForVendor]。同样,此设备id对于您的应用程序将是唯一的。http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor
发布于 2013-04-11 10:45:25
这是RFC6中的新特性,它为您提供了一个符合iOS 4122的UUID。
[[NSUUID UUID] UUIDString];
发布于 2013-04-11 10:53:47
使用此CFUUIDCreate()创建UUID:
+ (NSString *)GetUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}而且UDID只在iOS 5中被弃用。
https://stackoverflow.com/questions/15939819
复制相似问题