我知道[[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;
}
Run Code Online (Sandbox Code Playgroud)
如果我的方法未经Apple批准,我可以使用哪种方法获取唯一标识符?
这个项目与您正在做的事情类似: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];
}
Run Code Online (Sandbox Code Playgroud)
和@ JeffWolski的使用方法:
[[NSUUID UUID] UUIDString];
Run Code Online (Sandbox Code Playgroud)
如果您不需要设备ID在应用程序之间保持一致,只需要一种方法来识别您自己的特定设备.如果您需要在应用程序之间工作的设备ID,则需要使用您的代码或开源项目来使用设备MAC地址.
UPDATE
我刚刚找到另一个解决方案 你可以用[[UIDevice currentDevice] identifierForVendor].同样,此设备ID对您的应用来说也是唯一的.http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor