NSUserdefaults 持久化

发布于 2024-10-06 02:05:00 字数 586 浏览 0 评论 0原文

快问。我的应用程序中有一个密码系统,如果输入了太多不正确的密码,我想提供“锁定”应用程序的选项。我可以轻松地做到这一点,通过使用一个设置一些默认键的 UISwitch,这将切换另一个锁定应用程序的键集。抱歉,如果这令人困惑,但我真正的问题是,如果我执行以下操作:

// in the failure function
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"appIsLocked"];

// in didFinishLaunching
if( ![[NSUserDefaults standardUserDefaults] boolForKey:@"appIsLocked"] )
{
  // launch normally
}

首先,如果用户删除应用程序,然后从 iTunes 重新安装它,userDefaults 是否会被重置?例如,应用程序会自动解锁吗?其次,如果应用程序被锁定,苹果对我退出应用程序有何感受?这可能吗?或者,我应该只显示一个屏幕,显示它已锁定,请重新安装。当用户卸载我可以在其中运行清理的应用程序时,是否有一个函数被调用?

谢谢,如果问题太漫无目的,我们深表歉意。

Quick question. I have a passcode system in my app, that I want to give the option of "locking" out the app, if too many incorrect passcodes are entered. I can easily do this, by having a UISwitch that sets some defaults key, that would toggle another key set which would lock the app. Sorry if that is confusing, but the real question I have is, if I do something like:

// in the failure function
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"appIsLocked"];

// in didFinishLaunching
if( ![[NSUserDefaults standardUserDefaults] boolForKey:@"appIsLocked"] )
{
  // launch normally
}

Firstly, if the user deletes the app, then reinstalls it, from say iTunes, will the userDefaults be reset? As in, will the app be unlocked automagically? And secondly, how does apple feel about me just quitting the app if it is locked? Is that possible? Or, should I just show a screen that says it is locked, please reinstall. Is there a function that gets called when the user uninstalls the app that I could run cleanup in?

Thanks, and sorry if the question is too rambly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自此以后,行同陌路 2024-10-13 02:05:00

据我所知,没有办法真正退出该应用程序。调用 exit() 通常会让你被拒绝。苹果在这里特别这么说: http://developer.apple.com/ library/ios/#qa/qa2008/qa1561.html

所以我不建议这样做,只需保持应用程序打开并锁定即可。

另一方面,重新安装应用程序将解锁它,用户默认设置将被删除,如 Antwan 之前所说。

As far as I know, there is no way to acutally quit the app. Calling exit() will get you rejected usually. Apple specifically says so here: http://developer.apple.com/library/ios/#qa/qa2008/qa1561.html

So I wouldn't recommend doing that, just keep the app open and have it locked.

On the other hand, reinstalling the app will unlock it, the user defaults will be deleted as Antwan said before.

掀纱窥君容 2024-10-13 02:05:00

用户默认值位于应用程序包内,因此将被删除。
我认为当您退出时显示“您不允许使用此应用程序”对话时,苹果会批准您的应用程序。
请记住,当 iOS 设备越狱时,编辑用户默认值非常容易,因此将其保存在用户默认值中并不是保护它的好方法。

The userdefaults are inside the app bundle and will therefore be deleted.
I think that apple will approve your app when displaying a "You are not allowed to use this app" dailog when you quit.
Keep in mind that it is really easy to edit the user defaults when the iOS device is jailbroken and that therefore saving it in the user defaults isn't a good method of securing it.

几味少女 2024-10-13 02:05:00

以编程方式退出应用程序确实不是首选。您应该使用专门通知用户他们被锁定的视图来锁定用户。

此外,当从设备中删除任何一个应用程序时,该应用程序的用户默认值都会被删除。实现持久锁定的唯一方法是远程存储锁定信息,例如存储在您的一台服务器上(在这种情况下,请强烈考虑实用性)。

专业提示:对密码进行哈希处理,不要将其以明文形式存储,然后比较哈希值。

It's really not preferred to quit an app programmatically. You should lock the user out with a View dedicated to informing the user that they are locked out.

Additionally, User Defaults for any one app are deleted when the app is removed from the device. The only way to have a persistent lockout is to store the lockout information remotely, like on one of your servers (consider practicality strongly in this case).

Protip: hash the passcode, don't store it in plaintext, and compare the hashes.

淡紫姑娘! 2024-10-13 02:05:00

尽管由于用户认为应用程序崩溃了而强烈建议不要这样做,但您仍然可以使用函数 exit();。我不知道这是不鼓励的,我使用它的方式是我将我的应用程序动画化为黑屏,一旦动画完成,它就会退出应用程序。对于用户来说,这种方法似乎并没有导致应用程序崩溃。

我目前在应用程序商店中有一个使用此功能的应用程序,因此您的应用程序可能会也可能不会被拒绝。如果您仍然想采用这种退出应用程序的方法,请使用以下代码段。

exit(0);

Although it is strongly discouraged due to the fact that it seems to the user as if the application has crashed, you can still use the function exit();. I was not aware that this was discouraged, and the way I used it was I animated my app to fade to a black screen and once the animation finished it exited the app. This approach did not seem like the app had crashed to the user.

I currently have an app on the app store which uses this functionality, therefore your app may or may not be rejected. If you still want to approach this method of exiting your application, use the following code segment.

exit(0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文