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..
-
Are you creating the plist file at runtime ? – Midhun MP May 07 '13 at 06:28
-
Yes I am.. after the 1st product is purchased. – user123 May 07 '13 at 06:35
2 Answers
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!

- 1
- 1

- 11,470
- 2
- 21
- 29
-
Thanks for the recommendation. I am storing information of purchased products. Even if I encrypt it, it wouldn't make much of a difference since the decryption algorithm will be the same within my app. Someone can buy something and share the plist file easily.. I am not really sure if keychain will suit for that purpose but I will certainly check that out.. – user123 May 07 '13 at 06:32
-
Yeah, then in your case, `NSUserDefaults` or keychain is the way to go. – Fahri Azimov May 07 '13 at 09:43
-
And, for each device you could use different keys for encrypting, like `UDID`, which is deprecated, or unique strings, UUID for example. – Fahri Azimov May 07 '13 at 09:45
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 :
Also you can use the UUID
class method of NSUUID
class for creating an unique id.

- 103,496
- 31
- 153
- 200
-
Thanks.. identifierForVendor and uniqueIdentifier seem like returning different results. If someone buys something on iOS 5 and later he upgrades OS to 6+ then this wouldn't work. Am I right? – user123 May 07 '13 at 07:33
-
@user968173 Yes. In iOS 6 the uniqueIdentifier Won't work. So for iOS 5 use uniqueIdentifier and store the value in NSUserDefaults. Or simply use NSUUID class for creating unique Identifier and save it in database. – Midhun MP May 07 '13 at 08:59