【问题标题】:UDID Replacement?UDID 替换?
【发布时间】:2013-04-11 02:42:01
【问题描述】:

我知道[[UIDevice currentDevice] uniqueIdentifier] 被拒绝了,我使用了:

- (NSString *) uniqueDeviceIdentifier{
    NSString *macaddress = [[UIDevice currentDevice] macaddress];
    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];

    NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier];
    NSString *uniqueIdentifier = [stringToHash stringFromMD5];

    return uniqueIdentifier;
}

如果我的方法未经 Apple 批准,我可以通过什么方法获得唯一标识符?

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    此项目的功能与您正在做的类似:https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5。我相信它现在正在被Apple接受。要真正回答您的问题,没有其他(公共)方法可以获取不仅唯一而且对于每个应用程序都相同的 id。 @Vishal的使用方法:

    + (NSString *)GetUUID {
      CFUUIDRef theUUID = CFUUIDCreate(NULL);
      CFStringRef string = CFUUIDCreateString(NULL, theUUID);
      CFRelease(theUUID);
      return [(NSString *)string autorelease];
    }
    

    还有@JeffWolski的使用方法:

    [[NSUUID UUID] UUIDString];
    

    如果您不需要设备 ID 在应用之间保持一致并且只需要一种方法来识别您自己的特定设备,则可以使用。如果您需要在应用之间工作的设备 ID,则需要使用您的代码或开源项目来使用设备 MAC 地址。

    更新

    我刚刚找到了另一个解决方案。您可以使用[[UIDevice currentDevice] identifierForVendor]。同样,此设备 ID 对您的应用程序来说是唯一的。 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor

    【讨论】:

    • 你的方法行得通;但是,与其他方法一样,它对于您的应用程序来说是唯一的,因为您将捆绑包 ID 附加到 mac 地址。 mac 地址在设备上是唯一的,而捆绑包 ID 在应用程序和设备上是唯一的。如果您希望它对设备是唯一的(使其对每个应用程序都相同),您可以删除附加捆绑包 ID 的部分
    【解决方案2】:

    这是 iOS 6 中的新功能。它为您提供符合 RFC 4122 的 UUID。

    [[NSUUID UUID] UUIDString];

    【讨论】:

      【解决方案3】:

      使用此 CFUUIDCreate() 创建 UUID:

      + (NSString *)GetUUID {
        CFUUIDRef theUUID = CFUUIDCreate(NULL);
        CFStringRef string = CFUUIDCreateString(NULL, theUUID);
        CFRelease(theUUID);
        return [(NSString *)string autorelease];
      }
      

      UDID 仅在 iOS 5 中被弃用。

      【讨论】:

        【解决方案4】:

        您可以使用openUDID 替换它。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-03-12
          • 1970-01-01
          • 2012-03-26
          • 2019-11-11
          • 2012-04-09
          • 2013-10-13
          相关资源
          最近更新 更多