首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用CFUUIDCreate替换uniqueIdentifier?

如何用CFUUIDCreate替换uniqueIdentifier?
EN

Stack Overflow用户
提问于 2012-05-12 00:49:52
回答 1查看 8.7K关注 0票数 10

我正在试着激活APNS。由于uniqueIdentifier已被弃用,因此我尝试通过以下代码使用CFUUIDCreate

代码语言:javascript
复制
UIDevice *dev = [UIDevice currentDevice];
NSString *deviceUuid;
if ([dev respondsToSelector:@selector(uniqueIdentifier)])
    deviceUuid = dev.uniqueIdentifier;
else {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    id uuid = [defaults objectForKey:@"deviceUuid"];
    if (uuid)
        deviceUuid = (NSString *)uuid;
    else {
        CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
        deviceUuid = (__bridge NSString *)cfUuid;
        CFRelease(cfUuid);
        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
    }
}

如何用CFUUIDCreate替换uniqueIdentifier

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-12 01:43:01

*iOS< 6.0

代码语言:javascript
复制
// Create universally unique identifier (object)
CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
    
// Get the string representation of CFUUID object.
NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject);
CFRelease(uuidObject);

iOS >= 6.0

代码语言:javascript
复制
NSString* UDID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10555493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档