Saving important value - ios

Imagine my app as a list manager. On first launch, you have one empty list. You can add as many stuff in it as you want for free, but if you want more lists, you have to buy an In App Purchase. I have two types of IAP : you can purchase lists one-by-one, as a consumable item (which you can't transfer to another device), or purchase an "unlimited lists" item (non-consumable), which lets you add as many lists as you want, and all yourd devices benefit from it. Note that I will probably disable the first one if you bought the second one.
To handle this, I use a global var through my app. The variable represents the maximum number of lists you are allowed to have. At first launch, the value is "1". If you buy a single list, the value becomes "2", and so on. If you buy the "unlimited pack", the value is set to "-1". So if your current number of lists is less than what you're allowed to have, you can add new lists.
I need to save this value locally somehow, so for example if the user bought the unlimited pack, he can keep adding lists when he comes back in the app.
What is the best way to securely save this value ? I usually use NSUserDefaults but I'm not sure one can't change the values manually. Also, storing them online is not an option as you can use the app offline.
If you think my way of handling the IAP with this variable is not the right one, please don't hesitate to tell me how you'd do it. Thanks.

You can save it into iOS Keychain.
There is a library that helps dealing with it: https://github.com/ldandersen/STUtils/tree/master/Security
So, to save number of lists, you'll use it like
[STKeychain storeUsername:#"lists"
andPassword:#"1"
forServiceName:#"my_super_app"
updateExisting:YES
error:&error];
To retrieve:
[STKeychain getPasswordForUsername:#"lists"
andServiceName:#"my_super_app"
error:&error];

Related

Shopify API Customers orders_count Rails

I'm in the process of making an app that will update shipping depending on what your order_count is using ShopifyAPI::Customer.
One main thing I'm trying to accomplish is being able to reset the order_count to zero for all customers.
I have been trying:
order = ShopifyAPI::Customer.all
order.update_all(:orders_count, "0")
It works when I'm addressing a single customer, but not Customer.all. Is there a way I can work around this to update all customers in the db at once?
Can you actually change a valid orders_count? It would be pretty crazy in my mind if Shopify allowed that.
If I were you, and I am not, for sure, I would simply change my algorithm so that it is more of a "How many orders has this customer placed since last tuesday?". That way, I reward them if their purchases exceed that threshold of X.
In your case, you are trying to erase their legitimate order history to make your counter work, which I doubt works.
In the meantime, if you can indeed set that count to zero, just loop through all the customers, and for each one, save their count as zero. There is no one shot all customers call in Shopify API, just like there is no one shot anything. Every resource is a one-off.

NSUserDefaults or a backend?

I have to ship a simple app with a very tight deadline so I have no time to learn anything othen than what I know (meaning learning Core Data for example). Would it fine to use NSUserDefaults to store data for my app? It's almost like a check list app where users have list of items with some data accompanying each item.
Other than that I would be using a service like Parse which I can handle thanks to having built my last app with it.
Would Apple reject an app if you use NSUserDefaults for something other than settings/preferences?
Thanks!
From Apple's documentation:
The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default.
[...]
Values returned from NSUserDefaults are immutable, even if you set a mutable object as the value. For example, if you set a mutable string as the value for "MyStringDefault", the string you later retrieve using stringForKey: will be immutable.
In other words, this is not the place to store mutable application data.
If the checklist data is going to be modified by end users (i.e. adding new items, or editing the text of the items on the checklist) it really would be worthwhile to learn how to use Core Data. Over the years it really has become very easy to learn and use.
You can find a great series of Core Data tutorials at http://code.tutsplus.com/series/core-data-from-scratch--cms-653
If you're looking for something that's been updated for iOS 8 and Swift (although they're mainly syntax changes for the new language), you can check out http://www.raywenderlich.com/85578/first-core-data-app-using-swift.
Apple wouldn't reject even if you unnecessarily burden NSUserDefault. But users of your App will definitely uninstall it or OS will kill it if app crashes or hangs their iPhone.
NSUserDefault : is a fast way to access the data. it stores in (key,value) pair and lives as long as your app is installed in phone. Usually session based small amount of data is supposed to be stored in it. Not ur entire database.
Database (CoreData or Sqlite) : Behind the seen Coredata is also a sqlite with objects talking to each other(Think in terms of model instead of tables if using Coredata).
I simple suggest you use Coredata if your data by any chance is big or expected to get big. CoreData wont take much time.
Yes, you can store data in NSUserDefaults, which will be the quick and dirty method to store data locally.
You could use Core Data, though I prefer to just use FMDB and write my own SQLite statements. You could also use NSFileManager and just read and write everything to a JSON file. Parse will probably be overkill if all you are doing is storing a list of check list objects.
Go for NSUserDefault fro now !
When the App is submitted fro approval, look at SQlLite. this will be useful for the next projects.
Parse... sure but make sure it's not overkilling especially if you have limited amount of data
Good Luck !

Storing huge dictionary IOS

My app has it's own sql database with let's say 2000 rows.
I know that in future I will add some new and delete some old. Each row got prioritet parameter that changes in order of user interaction.
I want to store all prioritets locally so my future app updates would not erase them.
So the question is what is the best way of doing that? Remember that I will need fast access to those prioritets in future and they must be easily mutable.

Can an app discover programmatically when it was bought, downloaded, installed, and the price paid?

I would like for my app (a single SKU) to provide different initial conditions (e.g. starting in-game currency) depending on if it was installed for free or if the user paid to install it. The price will be changing from time to time.
Is it possible for the app to look up this information?
Note: this is not for in-app purchases; I know I can look that up using StoreKit.
It looks like there are hacks and workarounds that get you part way there but for what you're trying to do you need a fully working solution so it looks like you can't which is too bad, I love a good hack :)
Edit: future readers should read the comments for a full discussion.
One idea is to save the current date at the start of the program, to a variable that is nil until it is first set. Then you have the date when the app is first run.
You may also check the date of the Documents folder which is created when the App is downloaded.
If you store this date as a user preference variable then it is preserved event when you update the App.
Then you can compare that date to data you get from your server.

Storing app info for next load

I have an app that I want to use to store different people's data. For example, say you add person A, B, C to a table; then when you tap on them you can add more of their data - phone number, address etc.
I want to be able to store the info for every one of those entries in order to be able to display them when the app starts next time (and when I switch between the different table entries). Currently if I add data to a person's details, if I switch to another person, the data for the first one goes away as I'm not storing in any way.
I don't want to use Core Data as it's only for a low number of entries (about a dozen or so). Can anyone please give me an idea of how I could store each entry so as to pull it at run time (or whenever I tap on an entry that I've added details for already)?
Store each entry in an NSArray of NSDictionarys, which, in turn, can be stored in NSUserDefaults.

Resources