适用于 iOS 7.0 及更高版本的 iOS 设备的唯一标识
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24753537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unique Identification of iOS device for iOS 7.0 and above
提问by Karamjeet Singh
Looking for your help
寻求您的帮助
I am facing a problem while getting Device Identifier. Actually I am using a UIDevice+IdentifierAddition.h, NSString+MD5Addition.h classes to get Identifier, but its return same identifier for all my devicesi.e. iPhone 4s (iOS 7.1) & iPhone 5 (iOS 7.1.1).
我在获取Device Identifier时遇到问题。实际上我正在使用 UIDevice+IdentifierAddition.h、NSString+MD5Addition.h 类来获取标识符,但它为我的所有设备返回相同的标识符,即iPhone 4s (iOS 7.1) 和 iPhone 5 (iOS 7.1.1)。
Can any one have any solution for this problem. because I want a something unique for device specific. its my app requirement.
任何人都可以解决这个问题。因为我想要一个特定于设备的独特的东西。它是我的应用程序要求。
Important: I want to submit this app on app store, So please, answer must be as per the guidelines
重要提示:我想在应用商店提交这个应用,所以请回答必须按照指南
回答by rckoenes
Since iOS 7 it is no longer possible to get any unique device identifiers.
从 iOS 7 开始,不再可能获得任何唯一的设备标识符。
Your options are:
您的选择是:
- create your own unique ID and save it in the keychain.
- use the vendor ID, which will be reset if all the app by the same vendor are removed from the device.
回答by Muhammad Umair
Now it's possible in iOS 11.0+, Apple has introduced a new API called DeviceCheck API
with which developers can uniquely identify a device.
现在可以在iOS 11.0+ 中实现,Apple 引入了一个新的 API DeviceCheck API
,开发人员可以使用它来唯一地识别设备。
As mentioned in the documentation:
Using the DeviceCheck APIs, in combination with server-to-server APIs, you can set and query two bits of data per device, while maintaining user privacy. You might use this data to identify devices that have already taken advantage of a promotional offer that you provide, or to flag a device that you have determined to be fraudulent. The DeviceCheck APIs also let you verify that the token you receive comes from an authentic Apple device that includes your app.
将 DeviceCheck API 与服务器到服务器 API 结合使用,您可以设置和查询每台设备的两位数据,同时维护用户隐私。您可以使用此数据来识别已经利用您提供的促销优惠的设备,或者标记您确定为欺诈的设备。DeviceCheck API 还可以让您验证收到的令牌是否来自包含您的应用程序的真实 Apple 设备。
Also, check out the following WWDC17 video starting at 24 min: https://developer.apple.com/videos/play/wwdc2017/702/
另外,请查看以下 WWDC17 视频,从 24 分钟开始:https: //developer.apple.com/videos/play/wwdc2017/702/
EDIT:
编辑:
A thoroughly detailed tutorial on this Device Check
topic can be found here.
Device Check
可以在此处找到有关此主题的详尽教程。
回答by Avijit Nagare
In Objective c
在目标 c
NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
In Swift
在斯威夫特
var uniqueId=UIDevice.currentDevice().identifierForVendor.UUIDString as String
println("Your device identifires =>\(uniqueId)")
回答by nahlamortada
Unfortunately identifierForVendor changes when you uninstall your application so to guarantee that the it will not change save it in the keychain
不幸的是,当您卸载应用程序时,identifierForVendor 会发生变化,以确保它不会更改,将其保存在钥匙串中
I used pod 'SSKeychain' Homepage: https://github.com/soffes/sskeychain
我使用了 pod 'SSKeychain' 主页:https: //github.com/soffes/sskeychain
Here is the code
这是代码
+ (NSString *)getDeviceId {
NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"MY_KEY"];
if (strApplicationUUID == nil) {
strApplicationUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[SSKeychain setPassword:strApplicationUUID forService:appName account:@"MY_KEY"];
}
return strApplicationUUID;
}
回答by Mahesh
回答by Nik
[UIDevice uniqueIdentifier]; is deprecated in ios 5 and above.
[UIDevice uniqueIdentifier]; 在 ios 5 及更高版本中已弃用。
You can get identifier for vendor using this NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];
您可以使用此 NSString *udid = [[UIDevice currentDevice] uniqueIdentifier] 获取供应商的标识符;
and store this in keychain and use later on.
并将其存储在钥匙串中并稍后使用。
Also you can check for 1) NSUUID 2)CFUUID
您也可以检查 1) NSUUID 2)CFUUID
you will get detail description here Unique device identification in ios
您将在此处获得详细说明ios 中的唯一设备标识