如何在iOS 7中以编程方式获取iOS设备的UDID

4
我正在使用以下代码来显示设备的UDID。但它显示了空值,即2014-05-12 11:56:06.896 LoginScreen[195:60b] deviceUDID: (null)。
NSUUID *deviceId;
deviceId = [UIDevice currentDevice].identifierForVendor;
NSLog(@"deviceUDID: %@",deviceID);

对不起,我犯了一个愚蠢的错误。

这里的NSUUID实例是设备ID,我正在使用NSLog打印出deviceID :)

现在它对我有效了。感谢大家


1
https://dev59.com/WWw05IYBdhLWcg3w11W0 - iPatel
一个小提示:这应该是UUID而不是UDID:[http://nshipster.com/uuid-udid-unique-identifier/]。 - Rok Jarc
可能是从iOS 7测试人员获取UDID的重复问题。 - Arslan Ali
5个回答

5
为了获取设备的UUID,您可以使用以下代码行。
[[[UIDevice currentDevice] identifierForVendor] UUIDString];

但是你需要检查应用程序是在模拟器上运行还是在设备上运行。

希望这能帮到你。


@Popeye 那个 $ 符号是错误放置的。 - Shubhendu
好的,没问题,我不会移除我的评论。 - Popeye

3

苹果在iOS 7开始隐藏了所有公共API中的UDID。任何以FFFF开头的UDID都是伪造的ID。


那么您的意思是在iOS 7及以上版本中无法获取设备的UDID? - Brijesh Singh
可以使用广告标识符代替UDID。 - Gajendra Rawat
OP 询问 identifierForVendor 是否可用。advertisingIdentifier 可以通过设置被用户选择退出。 - Rok Jarc

0

Objective-C

NSString *strUUIDValue = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    NSLog(@"strUUIDValue : %@", strUUIDValue);

Screenshot for Objective-C

Swift 2 :

let UUIDValue = UIDevice.currentDevice().identifierForVendor!.UUIDString
        print("UUID: \(UUIDValue)")

Screenshot for Swift 2


0
NSString *string = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; 
string = [string stringByReplacingOccurrencesOfString:@"-" withString:@""]; 
string = [NSString stringWithFormat:@"%@%@",@"FFFFFFFF",string];

-1

试试这个

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

或者

   NSString *uuid = nil;
   CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
   if (theUUID) {
    uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
   [uuid autorelease];
   CFRelease(theUUID);
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接