【问题标题】:The [UIDevice uniqueIdentifier] become private in iOS 6.0[UIDevice uniqueIdentifier] 在 iOS 6.0 中变为私有
【发布时间】:2013-05-13 07:50:26
【问题描述】:

Apple 不允许将应用程序添加到使用 [UIDevice uniqueIdentifier] 的应用商店,因为该属性在 iOS SDK 6.0 中变为私有

什么是替代品?

【问题讨论】:

    标签: ios objective-c sdk uniqueidentifier


    【解决方案1】:

    您可以使用/创建“您自己的”UDID:

    +(NSString *)getUUID
    {
        CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
        NSString * uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
        CFRelease(newUniqueId);
    
        return uuidString;
    }
    

    您应该记住,此方法将在每次调用时产生不同的 id,因此您应该以某种方式将其持久化,因此它不是 UDID 的相同替代方案,但对于大多数用途来说,它甚至更好。

    【讨论】:

    • 我就是这么做的! (case curr iOS version
    • @evya: 1. 我看不出有理由在 6.0 中使用自定义的;只需为所有人​​使用自定义的。 2. 问题是“什么是替代方案?”,您可以随心所欲地坚持下去.. 3. 我可能应该对您的答案发表评论,但似乎用与该问题相关的唯一代码发布一个干净的答案会对寻求答案的人更有用。
    【解决方案2】:
    #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    
    - (NSString*)deviceId {
        NSString *udidString;
    
        if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            udidString = [defaults objectForKey:@"udidKey"];
            if (!udidString) {
                CFUUIDRef identifierObject = CFUUIDCreate(kCFAllocatorDefault);
                // Convert the CFUUID to a string
                udidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, identifierObject);
                [defaults setObject:udidString forKey:@"udidKey"];
                [defaults synchronize];
                CFRelease((CFTypeRef) identifierObject);
            }
    
        } else {
            udidString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        }
        return udidString;
    }
    

    如果在线收到警告:udidString = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; 这意味着 Xcode SDK 小于 6.0

    Xcode 4.3 包含 iOS SDK 5.1,Xcode 4.5 包含 iOS SDK 6.0)

    更新 Xcode iOS SDK:

    1. 只需下载 App Store 上可用的最新 Xcode(Apple 不提供仅下载 SDK 的选项)。
    2. 如果只想保留当前的 ​​Xcode 版本:

      • 下载最新的 Xcode 版本。
      • 从以下位置复制 iOS SDK 库:

    newestXcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/

    oldXcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/

    重新打开旧的 Xcode 就可以了!

    【讨论】:

    • 虽然你不能在你的应用程序中使用设备UDID,因为它被Apple完全禁止,否则你的应用程序将被拒绝,我已经发布了有关它的详细信息,你可以阅读它here
    猜你喜欢
    • 2013-05-17
    • 2023-03-06
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多