如何在iOS7中以编程方式获取设备UDID.[[UIDevice currentDevice] uniqueIdentifier]我用过这段代码这是不推荐使用的iOS7.如何获取设备UDID.删除应用程序时重新设置UDID字符串,重新安装意味着UDID变得不同.
cod*_*cat 34
它对所有版本都是100%的工作
苹果使用ASIdentifierManager类参考推荐的其他最佳选项
ios7-APP-向后兼容与 - 关于唯一的ios5-标识符
此链接告诉您如何处理和使用自定义框架
的UIDevice-唯一标识符,财产被弃用的 - 什么 - 现在
iOS 9
NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"20B0DDE7-6087-4607-842A-E97C72E4D522"];
NSLog(@"%@",uuid);
NSLog(@"%@",[uuid UUIDString]);
Run Code Online (Sandbox Code Playgroud)
要么
它仅支持ios 6.0及以上版本
要使用的代码 [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSUUID *deviceId;
#if TARGET_IPHONE_SIMULATOR
deviceId = [NSUUID initWithUUIDString:@"UUID-STRING-VALUE"];
#else
deviceId = [UIDevice currentDevice].identifierForVendor;
#endif
Run Code Online (Sandbox Code Playgroud)
ios 5使用喜欢
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
}
Run Code Online (Sandbox Code Playgroud)
Tap*_*Pal 19
出于安全/隐私原因,iOS 6+中不再提供UDID.而是使用identifierForVendor或advertisingIdentifier.
请仔细阅读此链接.
NSString* uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+
NSLog(@"UDID:: %@", uniqueIdentifier);
Run Code Online (Sandbox Code Playgroud)
适用于iOS 8+的更新
+ (NSString *)deviceUUID
{
if([[NSUserDefaults standardUserDefaults] objectForKey:[[NSBundle mainBundle] bundleIdentifier]])
return [[NSUserDefaults standardUserDefaults] objectForKey:[[NSBundle mainBundle] bundleIdentifier]];
@autoreleasepool {
CFUUIDRef uuidReference = CFUUIDCreate(nil);
CFStringRef stringReference = CFUUIDCreateString(nil, uuidReference);
NSString *uuidString = (__bridge NSString *)(stringReference);
[[NSUserDefaults standardUserDefaults] setObject:uuidString forKey:[[NSBundle mainBundle] bundleIdentifier]];
[[NSUserDefaults standardUserDefaults] synchronize];
CFRelease(uuidReference);
CFRelease(stringReference);
return uuidString;
}
}
Run Code Online (Sandbox Code Playgroud)
在Swift中你可以得到像这样的设备UUID
let uuid = UIDevice.currentDevice().identifierForVendor.UUIDString
println(uuid)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58799 次 |
| 最近记录: |