How should I use identifierForVendor during development?

陌路散爱 提交于 2019-11-29 18:08:16

问题


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?


回答1:


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.

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

Note that you need to replace SOME-STATIC-UUID-STRING with a real UUID string.



来源:https://stackoverflow.com/questions/18905091/how-should-i-use-identifierforvendor-during-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!