在 iOS 游戏中存储高分的安全方法?
Secure way of storing a highscore in iOS game?
我正在开发一款即将完成的游戏,所以我不得不在本地存储用户的高分。在游戏中存储高分的最安全方法是什么?一些人认为 NSUserDefaults 不是一种安全的方式,因为用户可以操纵他们的高分,例如当他们越狱时。
我是 Spritekit 编程的新手,请问您能否建议存储高分的最佳方式,这种方式不太复杂。如果你也提供一个例子就太好了,否则就可以了。
谢谢
您无法保护您的分数免受越狱用户的侵害。因为他们有时甚至可以在将高分上传到游戏中心等之前操纵它。
努力也必须与结果相匹配。您可以制作一个 CoreData-DB 来保存三个数字。但这太过分了。您必须编写大量代码才能保存一个数字。
所以我认为对于大多数没有带有物品、选择等复杂系统的游戏来说,使用 NSUserDefaults 基本上是可以的。
所以我会保持简单并使用 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")
}
}
我正在开发一款即将完成的游戏,所以我不得不在本地存储用户的高分。在游戏中存储高分的最安全方法是什么?一些人认为 NSUserDefaults 不是一种安全的方式,因为用户可以操纵他们的高分,例如当他们越狱时。
我是 Spritekit 编程的新手,请问您能否建议存储高分的最佳方式,这种方式不太复杂。如果你也提供一个例子就太好了,否则就可以了。
谢谢
您无法保护您的分数免受越狱用户的侵害。因为他们有时甚至可以在将高分上传到游戏中心等之前操纵它。
努力也必须与结果相匹配。您可以制作一个 CoreData-DB 来保存三个数字。但这太过分了。您必须编写大量代码才能保存一个数字。
所以我认为对于大多数没有带有物品、选择等复杂系统的游戏来说,使用 NSUserDefaults 基本上是可以的。
所以我会保持简单并使用 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")
}
}