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

查看:175
本文介绍了如何唯一标识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.

下面是一些code我较早前复制的互联网络,并且仍然使用它直到今天,将设法找到源,并在更新一点我的答案。
编辑:<一href=\"http://stackoverflow.com/questions/427180/how-to-create-a-guid-uuid-using-the-iphone-sdk\">Source

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

这将生成并存储UUID您在UserDefaults:

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追加到过这样你就可以知道是什么挂钩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天全站免登陆