简体   繁体   中英

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 eg 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

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")
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM