ah786
ah786

Reputation: 71

Secure way of storing a highscore in iOS game?

I'm developing a game which is almost done so I've come to a point where I have to store the user's highscore locally. What is the most secure way of storing the highscore in a game? Some suggest that NSUserDefaults is not a secure way as users can manipulate their highscore e.g when they jailbreak.

I'm a newbie to Spritekit programming so can you please advice the best way of storing the highscore which is not too complicated. If you provide an example also then it would be great, otherwise it's fine.

Thanks

Upvotes: 0

Views: 948

Answers (1)

Christian
Christian

Reputation: 22343

You can't protect your score against jailbreak-users. Because they sometimes even can manipulate the highscore before uploading it to gamecenter etc.

Also the effort has to match the result. You could make a CoreData-DB to save three numbers. But it would be an overkill. You'd have to write a huge amount of code to save one number.

So I think for most games without complex systems with items, choices etc. it's mostly okay to use NSUserDefaults.

So I would keep it simple and use NSUserDefaults

func saveHighscore(highscore:Int){

    //Check if there is already a highscore
    if let currentHighscore:Int = NSUserDefaults.standardUserDefaults().valueForKey("highscore") as? Int{
        //If the new highscore is higher then the current highscore, save it.
        if(highscore > currentHighscore){
            NSUserDefaults.setValue(highscore, forKey: "highscore")
        }
    }else{
        //If there isn't a highscore set yet, every highscore is higher then nothing. So add it.
        NSUserDefaults.setValue(highscore, forKey: "highscore")
    }
}

Upvotes: 4

Related Questions