如果不是“IPHONE UDID”该使用什么?

发布于 2024-09-26 06:28:51 字数 232 浏览 4 评论 0原文

哇...看看本周网上有关使用 iPhone UDID 的所有“恐慌故事”。

 [[UIDevice currentDevice] uniqueIdentifier]

我们应该使用什么来代替?

如果手机被卖给另一个用户...并且应用程序已根据手机的 UDID 在远程服务器上存储了一些数据,该怎么办?

(当然,我想避免应用商店的“加密限制”的问题。)

Wow... look at all the "panic stories" online this week regarding using an iPhone's UDID.

 [[UIDevice currentDevice] uniqueIdentifier]

What SHOULD we be using instead?

What if the phone is sold to another user... and an app has stored some data on a remote server, based on the phone's UDID?

(Of course, I want to avoid the problems with the app store's "encryption restrictions".)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

听你说爱我 2024-10-03 06:28:52

一种解决方案是让应用程序发布免费的应用内购买。

此购买将是:

  1. 可追踪,具有仅对您的应用有意义的唯一编号(购买)编号。

  2. 可移动,如果用户切换设备

  3. 可检索,如果应用被删除(或手机被擦除并重新加载) - 应用内购买可以恢复。

One solution would be to have the application issue a free in-app purchase.

This purchase would be:

  1. Trackable, with a unique number (purchase) number which would be meaningful only to your app.

  2. Movable, if the person switches devices

  3. Retrievable, if the app is deleted (or the phone is wiped and reloaded) - the In-App purchases can be restored.

oО清风挽发oО 2024-10-03 06:28:52

苹果的文档说:

“不要使用 uniqueIdentifier 属性。要创建唯一的
特定于您的应用程序的标识符,您可以调用 CFUUIDCreate
函数创建 UUID,并将其写入默认数据库
NSUserDefaults 类。”

这是一个快速片段:

CFUUIDRef udid = CFUUIDCreate(NULL);

NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);

Apple's documentation says:

"Do not use the uniqueIdentifier property. To create a unique
identifier specific to your app, you can call the CFUUIDCreate
function to create a UUID, and write it to the defaults database using
the NSUserDefaults class."

Here's a quick snippet:

CFUUIDRef udid = CFUUIDCreate(NULL);

NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);
情释 2024-10-03 06:28:51

为什么不使用 Mac 地址,然后可能将其散列起来。

这里有一个出色的 UIDevice-Extension 类别

    - (NSString *) macaddress
{
    int                 mib[6];
    size_t              len;
    char                *buf;
    unsigned char       *ptr;
    struct if_msghdr    *ifm;
    struct sockaddr_dl  *sdl;

    mib[0] = CTL_NET;
    mib[1] = AF_ROUTE;
    mib[2] = 0;
    mib[3] = AF_LINK;
    mib[4] = NET_RT_IFLIST;

    if ((mib[5] = if_nametoindex("en0")) == 0) {
        printf("Error: if_nametoindex error\n");
        return NULL;
    }

    if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 1\n");
        return NULL;
    }

    if ((buf = malloc(len)) == NULL) {
        printf("Could not allocate memory. error!\n");
        return NULL;
    }

    if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 2");
        return NULL;
    }

    ifm = (struct if_msghdr *)buf;
    sdl = (struct sockaddr_dl *)(ifm + 1);
    ptr = (unsigned char *)LLADDR(sdl);
    NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 
                           *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    // NSString *outstring = [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X", 
    //                       *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    free(buf);

    return outstring;
}

您可以可能会用模型来散列这个吗?

Why not use the Mac Address and possibly then hash it up.

There is an excellent UIDevice-Extension Category here

    - (NSString *) macaddress
{
    int                 mib[6];
    size_t              len;
    char                *buf;
    unsigned char       *ptr;
    struct if_msghdr    *ifm;
    struct sockaddr_dl  *sdl;

    mib[0] = CTL_NET;
    mib[1] = AF_ROUTE;
    mib[2] = 0;
    mib[3] = AF_LINK;
    mib[4] = NET_RT_IFLIST;

    if ((mib[5] = if_nametoindex("en0")) == 0) {
        printf("Error: if_nametoindex error\n");
        return NULL;
    }

    if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 1\n");
        return NULL;
    }

    if ((buf = malloc(len)) == NULL) {
        printf("Could not allocate memory. error!\n");
        return NULL;
    }

    if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 2");
        return NULL;
    }

    ifm = (struct if_msghdr *)buf;
    sdl = (struct sockaddr_dl *)(ifm + 1);
    ptr = (unsigned char *)LLADDR(sdl);
    NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 
                           *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    // NSString *outstring = [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X", 
    //                       *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    free(buf);

    return outstring;
}

You could possibly hash this with the model?

肤浅与狂妄 2024-10-03 06:28:51

正如我今天早上在这篇文章中所问的那样,有一些替代方案:

1-首先,按照Apple的建议,识别每次安装识别每个设备。
因此,您可以使用 CFUUIDRef。示例:

NSString *uuid = nil;
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
  uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
  [uuid autorelease];
  CFRelease(theUUID);
}

2-如果您关心全球唯一标识符,那么您可以将此标识符存储在 iCloud 上。

3-最后,如果您确实需要在应用程序重新安装后保留的标识符(这种情况不会经常发生),您可以使用钥匙串(Apple 的钥匙串文档)。
但苹果团队会喜欢吗?

As I asked this morning in this post, there are some alternative :

1- first, as Apple recommands, identify per install instead of indentifying per device.
Therefore, you can use CFUUIDRef. Example :

NSString *uuid = nil;
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
  uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
  [uuid autorelease];
  CFRelease(theUUID);
}

2- If you care about a worldwide unique identifier, so you could store this identifier on iCloud.

3- At last, if you really need an identifier that remains after app re-install (that not occurs so frequently), you can use Keychains (Apple's keychain doc).
But will apple team like it ?

失与倦" 2024-10-03 06:28:51

UUID 刚刚贬值,所以会存在一段时间,苹果还没有对这种贬值说太多,我会等到他们对此有更多的说法,也许他们会提供一些替代方案。

UUID is just depreciated and so will be around for a while, Apple have not said much about this depreciation much yet, I would wait until they have more to say about this and maybe the will offer some alternative.

断桥再见 2024-10-03 06:28:51

像这样:

@interface UIDevice (UIDeviceAppIdentifier)
@property (readonly) NSString *deviceApplicationIdentifier;
@end

@implementation UIDevice (UIDeviceAppIdentifier)
- (NSString *) deviceApplicationIdentifier
{ 
  static NSString     *name    = @"theDeviceApplicationIdentifier";
  NSUserDefaults  *defaults = [NSUserDefaults standardUserDefaults];  
  NSString              *value     = [defaults objectForKey: name];

  if (!value)
    {
      value = (NSString *) CFUUIDCreateString (NULL, CFUUIDCreate(NULL));    
      [defaults setObject: value forKey: name];
      [defaults synchronize];
  }
  return value;
}
@end

iOS 文档或多或少描述了使用 CFUUIDCreate() 创建标识符并建议使用 UserDefaults 来存储它。

Like this:

@interface UIDevice (UIDeviceAppIdentifier)
@property (readonly) NSString *deviceApplicationIdentifier;
@end

@implementation UIDevice (UIDeviceAppIdentifier)
- (NSString *) deviceApplicationIdentifier
{ 
  static NSString     *name    = @"theDeviceApplicationIdentifier";
  NSUserDefaults  *defaults = [NSUserDefaults standardUserDefaults];  
  NSString              *value     = [defaults objectForKey: name];

  if (!value)
    {
      value = (NSString *) CFUUIDCreateString (NULL, CFUUIDCreate(NULL));    
      [defaults setObject: value forKey: name];
      [defaults synchronize];
  }
  return value;
}
@end

the iOS documentation more or less describes use of CFUUIDCreate() to create an identifier and suggests using UserDefaults to store it.

苦妄 2024-10-03 06:28:51

推荐的方法是使用 UUID 生成,并将其与用户自己愿意提供给应用程序的内容相关联。

然后,将该数据存储在外部,以便可以再次检索。可能还有其他方法可以轻松做到这一点,但这是推荐的方法。

The recommended way is by using UUID generation, and associate that with something that the user him/herself is willing to provide to the app.

Then, store this data externally, where it could be retrieved again. There are probably other ways to do this easily, but this is the recommended way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文