Search Unity

PlayerPrefs and app updates

Discussion in 'iOS and tvOS' started by Alex, Apr 9, 2009.

  1. Alex

    Alex

    Joined:
    Nov 19, 2008
    Posts:
    122
    Hey all,

    We're about to push out an update for an iPhone app, and had a question... if a user downloads an update, is their PlayerPrefs file wiped?
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    May I add a question to this post...

    Where is this data stored? The iPhone docs weren't updated with this info.

    file:///Applications/Unity%20iPhone/Documentation/ScriptReference/PlayerPrefs.html

    only describes the OSX, Windows and Web player versions...
     
  3. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    Your player prefs will not be wiped when users download an update. As for little angel's question, I'm not 100% sure.
     
  4. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Player prefs are stored in one of the app's data directories (can't recall which one off the top of my head) and are backed up by iTunes when you sync. When you update, the app is erased, the new app is installed, and the prefs are restored to the app's directory.
     
  5. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    Resurrecting another old thread...

    What if the player downloaded my game and hasn't synced or backed up with iTunes, then downloads my update straight to the phone? Is the data intact or overwritten?

    And what if the player deleted the game from the phone before getting the update...say the just went to the iTunes link and "rebought it" for free?

    My update is coming just a few weeks after initial release so this is a possible scenario.
     
  6. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    Sorry to bump this so soon, but I really need to know this. I have an update pending an answer to these questions.

    Thanks :oops:
     
  7. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
    If he downloads the update straight from his iphone the PlayerPrefs will be untouched.

    Deleting it from your iphone and rebuy it will result in deleted PlayerPrefs.

    Don't know what it does when you sync with iTunes again.
     
  8. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    Thank you for the fast answer.

    Now if I can get an answer for that last bit:


    I need to know what happens in this instance. Would the current playerprefs be completely erased, merged....?

    Dealing with high score cheaters and want to cover all the possible "loop holes" without deleting everyone else's scores.

    Thank you
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's nothing special about PlayerPrefs, it's just a wrapper for NSUserDefaults.

    --Eric
     
  10. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
    You can't stop the PlayerPref cheating. The problem lies with the JailBroken iPhones. Those guys can open up the PlayerPrefs file and change whatever they want to whatever they like.

    But as I think of it, you do got the Unity piracy check in your game right? (If you can't reach a highscore you can't temper with it either ;)
     
  11. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    I did some sneaky stuff outside of playerprefs to thwart those cheaters.

    Can you link me to the Unity Piracy Check thing? I don't have it...that would be great!

    Thank you very much!!!
     
  12. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
    Use the boolean of iPhoneUtils.isApplicationGenuine.

    I have two variants of it, disable all the menu buttons except the credits. Or change the behavior of the start game button and do a call to Application.OpenURL(itms://itunes-url) :)
     
  13. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    Cool. I just actually found a topic on that. Apparently there's no way to test it before submission but it seems simple enough. So some hacking the "playerprefs" (so to speak) will make it not pass the genuine test?

    Thanks again!
     
  14. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    I posted an "encryped playerprefs" class a while back. It's old code (was still learing Unity then), but it works, and should make it harder to hack. Do a search for encryptedplayerprefs.

    Basically it just stores everything as usual, but it also adds an md5 hash for each playerprefs var. If the hash isn't there or invalid, then it doesn't read the playerprefs values.

    Off course it's only good if you use it from the start - unless you add a script that converts old data to use this, and only perform this the first time the update is installed (so set another playerprefs var to indicate that it has been converted).
     
  15. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
    Well not exactly but I'll try to explain.

    If someone cracks your App (and it will happen!) then the IsGenuine will return false. If its false then you should not let them reach a highscore. If there is no highscore set in the PlayerPrefs, they can't change the score.

    On a non jailbroken iphone you can't access, and thus change, the PlayerPrefs file. So you hack highscores on a non jailbroken iphone.

    Thats smart, I like it!
     
  16. schplurg

    schplurg

    Joined:
    Mar 21, 2009
    Posts:
    208
    Thanks guys

    @smag...I saw that code before, I don't know if I can figure out how to use it. The game has been hacked already of course. I don't care so much. I just want to keep the highscores legit.

    I worked some code that will complicate things for highscore cheaters as well as save legit scores when the app is updated.

    The good news is that "Dave" is hovering around #20 in Top Paid Apps so I can't really complain too much, especially since this is my first game :)

    Thanks again so much!!!
     
  17. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
    I just checked your game this morning on AppAnnie and it is indeed doing very well! Congratulations!

    If you ever feel like inspiring other people or want to share stats, check this topic ;)