保存用户名和高分的最佳方法是什么 [英] what is the best way for saving username and High Score

查看:127
本文介绍了保存用户名和高分的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要保存一个双倍值(高分)和字符串(玩家名称)我应该用什么来获得这个。

In my app I need to save a double value (high score) and String (player name) what should i use to get this.

任何想法都将是很好。

谢谢

推荐答案

正如deanWombourne所说,你可以使用NSUserDefaults存储这些数据但不是很安全。如果您不想在空中存储这些数据,可以查看 SFHFKeychainUtils 存储在iPhone Keychain中。

As deanWombourne said, you can use NSUserDefaults to store these data but it isn't very secure. If you don't want to store this data "in the air", you can take a look to SFHFKeychainUtils by Buzz Andersen to store them in the iPhone Keychain.

首先,将SFHFKeychainUtils文件复制到您的项目中。单击SFHFKeychainUtils.m并单击Get Info。转到目标选项卡,检查目标附近的框是否已选中。如果没有,请检查它。按住Control键并单击Framework文件夹,然后选择Add Existing Framework。找到Security.framework并将其添加到您的项目中。还要检查是否通过对SFHFKeychainUtils.m执行相同的过程将此框架添加到目标中。现在打开您要使用此代码的实现文件,并添加到顶部 #importSFHFKeychainUtils.h

First of all, copy SFHFKeychainUtils files to your project. Click on the SFHFKeychainUtils.m and click on Get Info. Go to Target tab and check if the box near your target is checked. If not, check it. Control-click on your Framework folder and select Add Existing Framework. Find Security.framework and add it to your project. Check also that this framework is added to your target by doing the same procedure done for SFHFKeychainUtils.m. Now open you implementation file on where you want to use this code and add on the top #import "SFHFKeychainUtils.h".

这是一个关于如何使用此代码的小例子:

This is a little example on how to use this code:


// to store your data  
NSError *error = nil;  
[SFHFKeychainUtils storeUsername:kName andPassword:name forServiceName:kStoredName updateExisting:YES error:&error];  
[SFHFKeychainUtils storeUsername:kScore andPassword:score forServiceName:kStoredScore updateExisting:YES error:&error];  

// to get them back  
NSString *name = [SFHFKeychainUtils getPasswordForUsername:kName andServiceName:kScoredName error:&error];  
double score = [SFHFKeychainUtils getPasswordForUsername:kScore andServiceName:kScoredScore error:&error];  

// kName, kScore, kStoredName, kStoredScore are defined key but you can use also strings with @"your string here".
// It is important that when you store and get back a value, username and serviceName must be the same.

这篇关于保存用户名和高分的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆