Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wanted to share a somewhat unorthodox solution I found to this problem that has the HUGE advantage of not requiring a server. This method allows users to restore their consumable items if the app is deleted and reinstalled, but does not allow them to move the items to a new device (unless all their app data is copied over).</p> <p>Data stored in the keychain persists when an app is deleted and reinstalled. The keychain is intended for storing usernames and passwords, but you can also store information about consumable purchases in there. I used the KeychainItemWrapper class, available here: <a href="https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html" rel="nofollow noreferrer">https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html</a> </p> <p>Here is some sample code where I store and retrieve the number of paid hints that a user has remaining:</p> <pre><code>//Storing the consumable hint item count int hintsLeft = 100; KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"Hints" accessGroup:nil]; NSString *hintsString = [NSString stringWithFormat:@"%i",hintsLeft]; [wrapper setObject:hintsString forKey:(id)kSecValueData]; [wrapper release]; //Retrieving it KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"Hints" accessGroup:nil]; NSString *numHints = [wrapper objectForKey:(id)kSecValueData]; [wrapper release]; int retrievedHints = [numHints intValue]; </code></pre> <p>Notes: </p> <ul> <li><p>the key (id)kSecValueData can't be an arbitrary string, there is a set list of constants that you can use as the key.</p></li> <li><p>You will need to add the security framework</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload