xcode 在 iOS SDK 中识别每个 iphone 设备
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9410132/
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
identify each iphone device in iOS SDK
提问by vietstone
I need to determine each iOS device.
我需要确定每个 iOS 设备。
In the past SDKS, there's a way to identify UUID by the command
在过去的 SDKS 中,有一种通过命令来识别 UUID 的方法
[[UIDevice currentDevice] uniqueIdentifier];
But in iOS 5.0, this function is deprecated. Is there any way to do this similar task?
但在 iOS 5.0 中,此功能已弃用。有没有办法做这个类似的任务?
Thank you!
谢谢!
回答by Alex Terente
An alphanumeric string unique to each device based on various hardware details. (read-only) (Deprecated in iOS 5.0. Instead, create a unique identifier specific to your app.) @property (nonatomic, readonly, retain) NSString *uniqueIdentifier Special Considerations
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. Availability
Available in iOS 2.0 and later. Deprecated in iOS 5.0.
Related Sample Code
GKTank
Declared In UIDevice.h
基于各种硬件详细信息的每个设备唯一的字母数字字符串。(只读)(在 iOS 5.0 中已弃用。相反,创建特定于您的应用程序的唯一标识符。)@property(非原子、只读、保留)NSString *uniqueIdentifier 特殊注意事项
不要使用 uniqueIdentifier 属性。要创建特定于您的应用程序的唯一标识符,您可以调用 CFUUIDCreate 函数来创建 UUID,并使用 NSUserDefaults 类将其写入默认数据库。可用性
Available in iOS 2.0 and later. Deprecated in iOS 5.0.
相关示例代码
GKTank
在 UIDevice.h 中声明
So use CFUUIDCreate and you will get and uniqID and save it to the NSUDefaults.
Note that the CFUUIDCreate will give you a new id on each call. That is why you have to save it.
因此,使用 CFUUIDCreate,您将获得 uniqID 并将其保存到 NSUDefaults。
请注意, CFUUIDCreate 将在每次调用时为您提供一个新 ID。这就是为什么你必须保存它。
If you really need to know if the app was installed on that device you can read the mac address of the wifi card.
如果您真的需要知道该应用程序是否安装在该设备上,您可以读取 wifi 卡的 mac 地址。
回答by Muhammad Rizwan
For iOS 6 and latter you can use.
对于 iOS 6 及更高版本,您可以使用。
NSString *U_ID = [[NSUUID UUID] UUIDString];
NSString *U_ID = [[NSUUID UUID] UUIDString];
回答by Hiren
Please check the answer of @suchi here How to create a GUID/UUID using the iPhone SDK.
请在此处查看@suchi 的答案How to create a GUID/UUID using the iPhone SDK。
use [[UIDevice currentDevice] uniqueDeviceIdentifier] to retrieve the unique identifier (it's a hash of your Bundle ID + MAC address)
使用 [[UIDevice currentDevice] uniqueDeviceIdentifier] 检索唯一标识符(它是您的 Bundle ID + MAC 地址的哈希值)
use [[UIDevice currentDevice] uniqueGlobalDeviceIdentifier] to retrieve a global unique identifier (it's a hash of the MAC address, used for tracking between different apps).
使用 [[UIDevice currentDevice] uniqueGlobalDeviceIdentifier] 检索全局唯一标识符(它是 MAC 地址的哈希,用于在不同应用之间进行跟踪)。