我有一个使用钥匙串存储与身份验证相关信息的iOS应用程序。当应用程序被卸载时,我想从钥匙串中删除这些数据。如何获知应用程序被卸载/删除?
无法检测应用程序何时将从设备中删除。但是您可以检测应用程序在安装后首次启动的时间。我使用以下代码:
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunched"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunched"];
[[NSUserDefaults standardUserDefaults] synchronize];
//Here delete your info kept in your keychain. If not exist will not delete nothing, but if it exist mean your app has been installed again.
[removeYourPropertyInKeychain];
}