Is it possible to create a device specific .plist file -iOS

天大地大妈咪最大 提交于 2019-12-10 12:24:58

问题


I am storing some data in a plist file.. and I have realised that it can be shared. Is there a way where I can make .plist files device specific? Maybe UDID or something? Any ideas will be much appreciated..


回答1:


If you don't want others to see the contents of your .plist files, you could encrypt them with iOS provided encryption algorithms. Other simple way would be storing your sensitive data in the keychain, or NSUserDefaults without writing to file, which would be very device specific. Good Luck!




回答2:


UDID is banned from 1st May 2013.

From iOS 6 onwards there is one additional method called identifierForVendor. You can use this method for creating a unique Identifier for your App in each iOS device.

You can get it like:

NSString *idForApp = [[UIDevice currentDevice] identifierForVendor];

Save your plist using the idForApp. It'll be unique.

identifierForVendor

An alphanumeric string that uniquely identifies a device to the app’s vendor. (read-only)

@property(nonatomic, readonly, retain) NSUUID *identifierForVendor;

Discussion

The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

The value of this property may be nil if the app is running in the background, before the user has unlocked the device the first time after the device has been restarted. If the value is nil, wait and get the value again later.

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

Availability

Available in iOS 6.0 and later.

Declared In UIDevice.h

Reference :

  • UIDevice Class Reference
  • UDID Replacement

Also you can use the UUID class method of NSUUID class for creating an unique id.

NSUUID - UUID



来源:https://stackoverflow.com/questions/16411698/is-it-possible-to-create-a-device-specific-plist-file-ios

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