1

I've spent two days no reading and testing as there is a lot of info about this topic. Unfortunately I've found no solution yet. I can't implement my own authentication as this doesn't help with the issue I want to solve (see Backgrounding at the end of the question).

Here is my current best approach:

I'm generating a UUID thanks to https://stackoverflow.com/a/8677177/1443733 and storing it in the KeyChain as suggested with SwiftKeychainWrapper (https://github.com/jrendel/SwiftKeychainWrapper)

The short nice and sweet code for that is:

   let stored = KeychainWrapper.stringForKey("UUID")
    if stored != nil {
        Helper.log(TAG, msg: "retrieved from keychain: \(stored!)")
    } else {

        let theUUID = CFUUIDCreate(nil)
        let str = CFUUIDCreateString(nil, theUUID)

        Helper.log(TAG, msg: "generated UUID: \(str)")

        let ret = KeychainWrapper.setString(str, forKey: "UUID")
        Helper.log(TAG, msg: "setkeychain: \(ret)")
    }

But the UUID stored in the keychain seems to be per device and not per store ID as well.

When I store the UUID like above and login with a different Store ID on the device KeychainWrapper.stringForKey("UUID")still returns the value of the other user.

Isn't their a way to store a value in a store-id keychain?

It seems that I'm so close so I hope someone could point me in the right direction.

If that approach (with a keychain) can't succeed please let me know as well.

I reckon you can ask a different question as well: Is there some cryptic data I can read/generate or a store which changes with the Store Id currently used on a device?

Ohh... and Swift examples preffered ;)

Backgroundinfo: I use IAPs in my app and want to save the Store-Id of the user once a refresh of the receipt is valid. On each start of the app I check if the current Store-Id is the same as the saved one. If not I trigger immediately a refresh of the receipt. If it fails I fall back to the free version of the app.

Community
  • 1
  • 1
Soko
  • 774
  • 1
  • 7
  • 20

2 Answers2

1

iOS devices do not support multiple users.

If you want to differentiate between users you will have to do that in your app, perhaps with a user login. Then save a UUID per userID in the Keychain.

zaph
  • 111,848
  • 21
  • 189
  • 228
  • This won't work for my purpose. See the background info I added to the question. – Soko Jan 16 '15 at 12:01
  • What you are considering as a user ID is really an Apple Store ID. Each user has a user AppleID and that may be different than the Store ID. My wife and I share a Store ID and have different AppleIDs (iCloud)s as well as other per user settings such as email addresses and app settings. iOS devices do not support multiple users. – zaph Jan 16 '15 at 12:23
  • Thanks, I didn't know that. So there is no solution? No way to get a unique string for a Store ID? No place/database/keychain I can save something which changes/deletes on Store ID change on a device? So the only way to find out if friends "shared" an IAP or payed app is by regularly trigger a receiptrefresh and any the paying because he has to enter his password each time.... – Soko Jan 16 '15 at 17:21
0

As NSUserdefaults temporarily stores the UUID.so,after unistalling the app and again installing,the UID changes. So, UUID must be stored in keychain

Nishant Narola
  • 255
  • 3
  • 18