Apple建议使用[UIDevice currentDevice] .identifierForVendor。每次在iOS模拟器中运行其应用程序时,此值都会更改。
Apple recommends using [UIDevice currentDevice].identifierForVendor. The value of this changes every time one runs their application within the iOS simulator.
在我的应用程序中的初始功能需要我将设备识别为轻量身份验证的形式。这使得开发乏味,理想情况下,我可以在调试/运行会话中保持一个独特的价值。有没有任何建议,以完成这个?
Initial functionality in my application requires that I recognize the device as a form of light authentication. This makes development tedious, and ideally I could persist a unique value across debug / run sessions. Are there any recommendations for accomplishing this?
推荐答案这很漂亮清楚地记录了这个值在模拟器中构建和运行时会改变。在实际设备上,只有在用户从其设备中删除您的所有应用并重新安装应用时,该设置才会更改。
It's pretty clearly documented that this value will change when building and running in the simulator. On a real device, it will only change when the user deletes all of your apps from their device and reinstalls the app.
如果您希望模拟器应用使用一致标识符在开发期间可以定义该UUID并仅用于模拟器构建:
If you want the simulator app to use a consistent identifier during development you could define that UUID and use it for simulator builds only:
NSUUID *devId; #if TARGET_IPHONE_SIMULATOR devId = [NSUUID initWithUUIDString:@"SOME-STATIC-UUID-STRING"]; #else devId = [UIDevice currentDevice].identifierForVendor; #endif请注意,您需要将SOME-STATIC-UUID-STRING真正的UUID字符串。
Note that you need to replace SOME-STATIC-UUID-STRING with a real UUID string.
更多推荐
如何在开发过程中使用identifierForVendor?
发布评论