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 automa开发者_如何学Pythongically? 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.
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.
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.
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.
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);
精彩评论