且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS7中以编程方式获取设备UDID?

更新时间:2023-08-30 16:27:22

对所有版本都有效100%

It's work 100% to all the version

苹果推荐的其他***选择 ASIdentifierManager类参考

other best option recommend by apple use ASIdentifierManager Class Reference

ios7-app-backward-compatible-with-ios5 -regarding-unique-identifier

此链接告诉您如何处理和使用自定义框架

this link tell you how to handle and use custom framework

uidevice-uniqueidentifier-property-is不推荐使用的内容

iOS 9

NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"20B0DDE7-6087-4607-842A-E97C72E4D522"];
NSLog(@"%@",uuid);
NSLog(@"%@",[uuid UUIDString]);

它仅支持ios 6.0及更高版本

it support only ios 6.0 and above

使用[[[UIDevice currentDevice] identifierForVendor] UUIDString];

NSUUID *deviceId;
#if TARGET_IPHONE_SIMULATOR
deviceId = [NSUUID initWithUUIDString:@"UUID-STRING-VALUE"];
#else
deviceId = [UIDevice currentDevice].identifierForVendor;
#endif

要像使用iOS 5一样

ios 5 to use like

 if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
    // This is will run if it is iOS6
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
   // This is will run before iOS6 and you can use openUDID or other 
   // method to generate an identifier
}