Ios 如何用CFUUIDCreate替换uniqueIdentifier?

Ios 如何用CFUUIDCreate替换uniqueIdentifier?,ios,uniqueidentifier,Ios,Uniqueidentifier,我正在尝试激活APNS。由于不推荐使用uniqueIdentifier,因此我尝试将CFUUIDCreate与以下代码一起使用: UIDevice *dev = [UIDevice currentDevice]; NSString *deviceUuid; if ([dev respondsToSelector:@selector(uniqueIdentifier)]) deviceUuid = dev.uniqueIdentifier; else { NSUserDefault

我正在尝试激活APNS。由于不推荐使用
uniqueIdentifier
,因此我尝试将
CFUUIDCreate
与以下代码一起使用:

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

iOS<6.0 iOS>=6.0
您需要的一切都应该在这里:。下次再试试谷歌搜索吧。我已经读了堆栈上的所有帖子。。问题是:在这种情况下,我不知道如何实现
CFUUIDCreate
。我试图编辑您的问题以将其与之前提出的问题区分开来,但不清楚您在问什么。上面提供的代码有什么问题?它是否未编译,或者是否未按预期运行?代码运行良好,但uniqueIdentifier似乎已过时,我不想让我的应用程序被拒绝。此代码是非法的-等待它-Daaary。。得到你的名声,伙计!从iOS 6开始,您可以使用:NSString*UUID=[[nsuid-UUID]UUIDString]@对称:这在重新安装应用程序时总是不同的,您可以使用[[[UIDevice currentDevice]identifierForVendor]UUIString]而不是[[NSUID UUID]UUIString]。@John,这实际上是错误的。正如您在的文档中所看到的,当用户从设备中删除该供应商的所有应用程序并随后重新安装一个或多个应用程序时,该值会发生变化。我想说的是,对于大多数人来说,从同一个供应商那里获得剩余的应用程序实际上是一个边缘案例,因此UUID无论如何都会改变。@SriKrishna是的,但有一些限制。特别是,如果用户从特定供应商卸载所有应用程序,此ID将发生更改。
// 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);
NSString* UDID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];