简体   繁体   English

如何唯一识别iPhone / iPad?

[英]How can I uniquely identify iPhone/iPad?

I am trying to uniquely identify the iPhone/iPad mobile devices to save user data. 我试图唯一标识iPhone / iPad移动设备以保存用户数据。

I found out some, including 我发现了一些,包括

[NSString *UUID = [[NSUUID UUID] UUIDString];
[UIDevice currentDevice].identifierForVendor.UUIDString;

or take device token from 或从中获取设备令牌

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{ ... }

But the problem is that 但是问题是

  1. UUID changes everytime I close and restart the app (I experienced from debugging) 每当我关闭并重新启动应用程序时,UUID都会发生变化(我从调试中获得经验)
  2. identiferForVendor changes every time I delete and reinstall the app (or update the app) 每次我删除并重新安装应用程序(或更新应用程序)时,identiferForVendor都会更改
  3. I used device token to uniquely identify device across version updates, reinstall, but I learnt that it can be changed, and I am experiencing it from my updates and debugging in xCode. 我使用设备令牌在版本更新,重新安装之间唯一地标识设备,但是我了解到它可以更改,并且通过更新和在xCode中进行调试来体验它。

Since app store rejects using uniqueIdentifer, my question here is: Is there any way we can uniquely identify devices across any application updates, deletion, reinstallation? 由于应用程序商店拒绝使用uniqueIdentifer,因此我的问题是:有什么方法可以在任何应用程序更新,删除,重新安装中唯一地标识设备?

Use SSkeychain to store unique key permanently. 使用SSkeychain永久存储唯一密钥。 Take 4 files from sskeychain folder from this github example into your project 这个github示例的 sskeychain文件夹中获取4个文件到您的项目中

then after use this code to get unique identifier. 然后使用此代码获取唯一标识符。

-(NSString *)getUniqueDeviceIdentifierAsString
{

    NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];

    NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
    if (strApplicationUUID == nil)
    {
        strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
    }


    return strApplicationUUID;
}

This identifier will not change after deleting and reinstalling app. 删除并重新安装应用后,此标识符将不会更改。 I have used this and it is working perfect for me. 我已经用过了,它对我来说是完美的。

The closest thing I can think of is generating your own UUID and storing it in the device keychain . 我能想到的最接近的方法是生成您自己的UUID并将其存储在设备钥匙串中

By doing this, it will survive app deletion/reinstall, and if the user has enabled iCloud Keychain , it should also survive a device restore. 这样,它将在应用程序删除/重新安装后仍然有效,并且如果用户启用了iCloud钥匙串 ,则它也应该在设备还原后仍然有效。

To make things easier, you can use a keychain wrapper among the many available as open source ( one is here ). 为了使事情变得简单,您可以在许多可用的开源代码中使用钥匙串包装器( 此处是 )。

There's a great posting about this. 关于这个有一个很棒的帖子。

http://www.doubleencore.com/2013/04/unique-identifiers/ http://www.doubleencore.com/2013/04/unique-identifiers/

一种创造性的方法可能是(ab)使用wifi端口的MAC地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM