如何唯一识别ios设备 [英] how to identify ios device uniquely

查看:33
本文介绍了如何唯一识别ios设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的应用程序中,我必须让用户从不同的 iOS 设备登录到他们的帐户.目前我正在从令牌值进行用户身份验证.但为了支持多设备登录,我必须找到另一种方法来做到这一点.

In my current application,i have to let user to login from different iOS devices to their account. Currently i'm doing user authentication from a token value. but in order to support multiple device login i have to find another way for doing this.

因此,我想到了保存设备 uuid 以及用于身份验证 + 安全性的令牌.然后,我知道我不能使用设备的 uuid,而是必须使用 identifierForVendor,它可能会或可能不会始终提供用户或设备信息.

Thus, I thought of saving devices uuid along with token for authentication + security. Then, I come to know I can't use device's uuid, instead I have to use identifierForVendor which may or may not provide user or device information always.

那么,任何人都可以建议在 ios 中为同一用户帐户实现这种多设备登录功能的更好和正确的方法吗?

So, can anybody suggest the better and proper way of achieving this multiple device login feature for same user account in ios ?

推荐答案

正如您所知,不允许使用设备的 UUID,但是,您可以生成自己的 UUID 并将其存储在设备的 UserDefaults 中.

As you already know this using the device's UUID isn't allowed, however, you can generate your own UUID and store it on the devices' UserDefaults.

>

使用 identifierForVendor 并非 100% 可靠,因为它仅适用于 iOS6 及更高版本,并且用户可以选择不将其提供给您,这使其成为一个糟糕的选择.

using the identifierForVendor isn't 100% reliable, as it only works on iOS6 and above, and users have the ability to opt-out of giving it to you, which makes it a bad choice.

这是我前段时间从互联网上复制的一些代码,直到今天仍在使用它,将尝试找到源并稍微更新我的答案.来源

Here's some code I copied of the internets sometime ago and still use it till today, will try to find the source and update my answer in a bit. Source

这将为您在 UserDefaults 中生成和存储 UUID:

This will generate and store a UUID for you in UserDefaults:

- (NSString *)createUUID
{
  CFUUIDRef theUUID = CFUUIDCreate(NULL);
  CFStringRef string = CFUUIDCreateString(NULL, theUUID);
  CFRelease(theUUID);
  [[NSUserDefaults standardUserDefaults] setObject:(__bridge NSString *)string forKey:@"UUID"];
  [[NSUSerDefaults standardUserDefaults] synchronize];
  return (__bridge NSString *)string;
}

每当您需要读取生成的 UUID 时:

And whenever you need to read the generated UUID:

- (NSString*)UUID
{
    return [[NSUserDefaults standardUserDefaults] ObjectForKey:@"UUID"];
}

现在您也可以选择将您自己的用户 ID 附加到该 ID 上,这样您就可以知道哪个 UUID 与哪个用户相关联..

Now you have the choice to append your own user's ID to that too so you'll be able to know what UUID is linked to which user..

这只是它应该如何工作的粗略草图

This is just a rough sketch of how it should work

这篇关于如何唯一识别ios设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆