[英]Deleting Keychain when uninstalling iOS app
I have been reading several posts regarding this issue, for example Delete keychain items when an app is uninstalled and iOS autodelete Keychain items after uninstall? 我已经阅读了有关此问题的几篇文章,例如, 在卸载应用程序时删除钥匙串项以及在卸载后iOS自动 删除钥匙串项 ? . 。 They say that, when you uninstall an app, its Keychain
is not deleted, but the posts may be deprecated, is that the current behaviour? 他们说,当您卸载应用程序时,不会删除其“ Keychain
,但帖子可能已被弃用,这是当前行为吗?
On the other hand, if Keychain
is not really automatically deleted when the user uninstalls an app, I'm not clear about the way to do that yourself. 另一方面,如果用户卸载应用程序时Keychain
并没有真正自动删除,则我不清楚自己的方式。
EDIT: If Keychain
are not deleted when apps are uninstalled, what actually happens to all those residual Keychain
? 编辑:如果在卸载应用程序时未删除Keychain
,那么所有这些剩余的Keychain
实际上会发生什么? Does the system not handle that? 系统不处理吗?
There is no trigger to perform code when the app is deleted from the device. 从设备删除应用程序后,没有触发器可以执行代码。 Access to the keychain is dependent on the provisioning profile that is used to sign the application. 对钥匙串的访问取决于用于对应用程序进行签名的供应配置文件。 Therefore no other applications would be able to access this information in the keychain. 因此,没有其他应用程序能够访问钥匙串中的此信息。
I don't think you need to delete it. 我认为您不需要删除它。 I'm not sure how to delete it but I believe if you did set the keychain value to some certain then you can also assign the value of nil
or just empty string ""
. 我不确定如何删除它,但是我相信如果您确实将钥匙串的值设置为某个值,那么您还可以分配nil
的值或只是空字符串""
。 But this is not quite sure, just assuming. 但这并不确定,只是假设而已。
Hope it helps! 希望能帮助到你!
Try using UserDefaults to store a boolean that tracks when data is saved to the keychain. 尝试使用UserDefaults存储一个布尔值,该布尔值跟踪何时将数据保存到钥匙串。
Example: 例:
func someFunctionThatSavesToKeychain {
// Save to keychain
UserDefaults.standard.set(true, forKey: "isSavedToKeychain")
// Do other stuff
}
Then in AppDelegate in the didFinishLaunchingWithOptionsMethod 然后在AppDelegate中的didFinishLaunchingWithOptionsMethod
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if !UserDefaults.standard.bool(forKey: "isSavedToKeychain") {
// Delete data from Keychain
}
}
Since UserDefaults is cleared on application uninstall, the next time the user installs the application, that key-value will be gone therefore on start up, your AppDelegate will delete the residual Keychain data. 由于UserDefaults在应用程序卸载时被清除,因此下次用户安装该应用程序时,该键值将消失,因此在启动时,您的AppDelegate将删除残留的Keychain数据。
I've searched far and wide as well, this workaround is the closest you can get. 我也进行了广泛的搜索,这种解决方法是您可以获得的最接近的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.