Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Detect apple id change to re-prompt for purchases

Discussion in 'Unity IAP' started by GrayLightGames, Jun 25, 2018.

Thread Status:
Not open for further replies.
  1. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    Hi,

    I am implementing IAP in a game for iOS. I have one non-consumable in-app purchase that is basically a full version unlock. Once my app detects a purchase, I am setting a local flag that indicates it has been purchased. Upon loading the app, if the local flag indicates a previous purchase, I do not initialize purchasing at all and all content is unlocked. This allows my users to purchase a full version unlock and not need to remain connected to the internet to enjoy the game. It also maintains efficiency as there is no need to check purchasing once the unlock is purchased.

    However, I have realized that if a user signs out of the phone and logs in with a different Apple ID, the purchase remains. I am trying to access the Apple ID or some unique identifier that will allow me to detect when a different user is using the phone, re-lock the content, and spin up the purchasing again. The alternative as I see it is to leave the app vulnerable or to restore purchases every time the app starts, both of which are undesirable. In my experience, restoring purchases asks the user for their apple password every time, so I'd rather not do that on startup.

    Any help would be appreciated, and if there is a related post, I couldn't find it.

    Thanks much!
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You will want (and Apple requires) a Restore button. We do not do inventory management or user profiling in any way, so you will need to implement a user-specific mechanism to persist purchases. Using PlayerPrefs is one way, but it does get reset during reinstall.
     
  3. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    Thanks for the swift reply!

    Ah I didn't realize that PlayerPrefs was user-specific, makes sense. I saw some advice when I first started using Unity not to use it for app data so I haven't used it before... I'll do some experimenting. If it's user-specific, then it is exactly what I need. Reinstall reset won't be a problem. I have designed my app assuming that will be the case and I do have a Restore button.

    Thanks again, I'll post another reply once I get it working.
     
  4. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    After attempting to use PlayerPrefs, I'm noticing that it is not user-specific with regard to the Apple ID logged in on an iphone. Is this intentional?

    On initial install I set a PlayerPrefs keypair value to 0, on purchase it is set to 1. I then interpret the value every time the app starts. What I'm seeing is that it does in fact get set to 0 on install and 1 when I restore my purchase. Then, I force close, I log my Apple ID out of my iphone and log in with a different Apple ID that has not purchased. The log still shows that keypair value as 1 before anything else happens.

    Is PlayerPrefs supposed to correlate with the Apple ID? It doesn't appear to be functioning that way, unless I've done something wrong.

    I also noticed that Environment.UserName is "mobile" no matter who is logged in. So if PlayerPrefs needs to interact with that to store information for multiple users, then the Apple ID is not impacting the UserName. Has this functionality been verified with different Apple ID's?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    If there is no way to detect if a user change has occurred, then the app will be vulnerable to piracy. For example, someone purchases the full game unlock. Then they share their apple ID and password to everyone they know. Other people can log in with that Apple ID, unlock the game, then switch back to their own ID. Now they have access to the fully unlocked game for free. Does this concern make sense?

    If we aren't able to detect user change, then the alternative seems to be to restore purchases every time the game loads. This prompts users for their apple password potentially every time the app loads. It also means that I can't offer my users access to the purchased content while they are offline. As far as I can tell, it's either that or leave the app vulnerable. Is there another option?

    There are ways to identify users without violating privacy, but the mechanism would need to be provided by Apple... I'm looking into using Device.VendorIdentifier, but I believe this is device level, not user level. If this functionality is not provided by Apple, it would be great if someone on the Unity side could request that from Apple... I'm sure there would be more traction that way.

    PlayerPrefs doesn't resolve my concern if it is not user specific, whether it resets on reinstall or not.
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Purchases are always for the user making the purchases and are verified with the Apple ID. If you have some other mechanism for storing purchases across all users, then you would need to address that. And you mention "share their AppleID and password"? No one does that, and if they do, then yes, they get the purchases. And rarely does anyone share a device with any other person. Unless lending to a family member or friend, but even then they wouldn't likely log in with their own ID. I think your concerns are not valid in the real world. And yes, PlayerPrefs would indeed work in this case. A reinstall would reset the purchases to none, which is what you want. Only during the Apple Restore process (based on AppleID) would ProcessPurchase be fired for those items already purchased.
     
  8. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    So in the end, the answer is that there is no functionality I can utilize to detect a user change on an iOS device. That's all I'm asking about, not what happens when the game is reinstalled or what happens when someone restores purchases.

    I mean... we can argue about what people on the internet are willing to do to hack and pirate, but I didn't write this post to argue about anything. I'm a customer looking for support. If not sharing their ID, it doesn't seem out of the realm of possibility that someone would figure out they can log into their friend's device, unlock content, and then log out and have the content persist. Hopefully it's not someone with a blog. Even if you were right and "No one does that," they might. Information can spread fast on the internet and people like to get things for free.

    If it was easy to handle with Unity functionality, I'd add a couple of lines of code to handle the possibility. Apparently it's not. If you don't think it's worth escalating, that's fine too. I don't think I have anything beyond that to discuss on this post.

    Thanks.
     
    elsonxie likes this.
  9. syntakks

    syntakks

    Joined:
    Jan 11, 2020
    Posts:
    1
    You need to implement the Google play games and Apple Game Center plugins to allow player login to their accounts. Once they do you get their unique id which can be used to store the game progress.

    If the ID doesnt match what you have stored in PlayerPrefs, wipe the whole thing and replace with the new account?

    (I've never done this, just did some reading on it.)

    https://gamedev.stackexchange.com/a/110593
     
    elsonxie likes this.
  10. GrayLightGames

    GrayLightGames

    Joined:
    Jan 14, 2015
    Posts:
    30
    Thanks for the helpful reply!
     
Thread Status:
Not open for further replies.