如何在开发过程中使用identifierForVendor? [英] How should I use identifierForVendor during development?

查看:500
本文介绍了如何在开发过程中使用identifierForVendor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆