Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to store the flag in NSUserDefaults once purchase is done via In App Purchase?

I have some features which would be unlocked only after the purchase through in app purchase.

Is it fine if I store the flag value in NSUserDefaults to check whether app has been purchased or not?

Is it safe to store the flag in NSUserDefaults once purchase is done via In App Purchase?

like image 989
Parth Bhatt Avatar asked Jun 28 '11 09:06

Parth Bhatt


People also ask

What to save in UserDefaults?

This system, called UserDefaults can save integers, booleans, strings, arrays, dictionaries, dates and more, but you should be careful not to save too much data because it will slow the launch of your app.

Where are UserDefaults stored?

The user's defaults database is stored on disk as a property list or plist. A property list or plist is an XML file. At runtime, the UserDefaults class keeps the contents of the property list in memory to improve performance. Changes are made synchronously within the process of your application.

How much can I store in UserDefaults?

There is no specific number attached to “a small amount”, but everything you store in UserDefaults will automatically be loaded when your app launches – if you store a lot in there your app launch will slow down. To give you at least an idea, you should aim to store no more than 512KB in there.

What is NSUserDefaults in Swift?

Overview. The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user's preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed.


2 Answers

No, this is not safe.

The contents NSUserDefaults are stored in plain text. They can be accessed and modified with tools like iExplorer. This also works on devices that are not jailbroken.

This means that if you save the purchase information in the NSUserDefaults, users can unlock your content without doing an actual purchase.

To save the flags in a way that is not as easy to "crack", you could do one of the following:

  1. Save an additional salted hash of your stored information. Use the hash to validate that the user has not modified the information. You can find an implementation of this concept here.

  2. Save the flags in the keychain. Read more in Apple's Keychain Services Programming Guide. You can find several implementations of this concept on GitHub, e.g. Lockbox.

Update: As of iOS 8.3, the access to the app sandbox is somewhat restricted. While this adds some security, I would still not recommend using NSUserDefaults, as access to the sandbox is still possible for jailbroken devices, apps that have iTunes file sharing enabled, and of course devices running older versions of iOS.

like image 140
Theo Avatar answered Nov 15 '22 21:11

Theo


Yes, it's the best way. So you can tract through flag which are stored in NSUserDefault.

But, When you delete the app from device then it's value become FALSE. So it will ask for purchase again. But, it will not charge user for purchase same thing again.

Cheers.

like image 41
Nishant B Avatar answered Nov 15 '22 21:11

Nishant B