卸载应用程序时删除钥匙串项 [英] Delete keychain items when an app is uninstalled

查看:197
本文介绍了卸载应用程序时删除钥匙串项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 idandersen的scifihifi-iphone 代码进行钥匙串并使用

I am using idandersen's scifihifi-iphone code for keychain and save password using

[SFHFKeychainUtils storeUsername:@"User" andPassword:@"123"
              forServiceName:@"TestService" updateExisting:YES error:&error];

当我从设备中删除应用程序时,密码仍保留在钥匙串中。

When I delete the application from the device, the password remains in the keychain.

当用户从设备中删除应用程序时,我想从钥匙串中删除密码。我该怎么做?

I want to remove the password from the keychain when the user deletes the application from the device. How can I do this?

推荐答案

你可以利用 NSUserDefaults 。例如:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Clear keychain on first run in case of reinstallation
    if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun"]) {
        // Delete values from keychain here
        [[NSUserDefaults standardUserDefaults] setValue:@"1strun" forKey:@"FirstRun"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

    //...Other stuff that usually happens in didFinishLaunching
}

如果尚未设置应用程序的首次运行,则会在 NSUserDefaults 中检查并设置FirstRun键/值。有一个注释,你应该放置代码来删除钥匙串中的值。可以调用Synchronize以确保FirstRun键/值立即保留,以防用户在系统持续存在之前手动杀死应用程序。

This checks for and sets a "FirstRun" key/value in NSUserDefaults on the first run of your app if it's not already set. There's a comment where you should put code to delete values from the keychain. Synchronize can be called to make sure the "FirstRun" key/value is immediately persisted in case the user kills the app manually before the system persists it.

这篇关于卸载应用程序时删除钥匙串项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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