我在 Swift 2 中使用 SFSafariViewController 在带有 ios 9.1 (13B143) 的 iPad Air 2 上显示网页。每个网页都需要用户的凭据。但是,当用户按下注销按钮时,我需要清除这些凭据。我尝试过使用以下内容:
let allCreds = NSURLCredentialStorage.sharedCredentialStorage().allCredentials
for (protectionSpace, userCredsDict) in allCreds {
for (_, cred) in userCredsDict {
print("DELETING CREDENTIAL")
NSURLCredentialStorage.sharedCredentialStorage().removeCredential(cred, forProtectionSpace: protectionSpace, options: ["NSURLCredentialStorageRemoveSynchronizableCredentials" : true])
}
}
// Clear cookies
if let cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies {
for (cookie) in cookies {
print("DELETING COOKIE")
NSHTTPCookieStorage.sharedHTTPCookieStorage().deleteCookie(cookie)
}
}
// Clear history
print("CLEARING URL HISTORY")
NSURLCache.sharedURLCache().removeAllCachedResponses()
NSUserDefaults.standardUserDefaults().synchronize()
但它不起作用。事实上,“DELETING CREDENTIAL”和“DELETING COOKIE”永远不会被打印。此外,我可以完全从 iPad 上删除该应用程序并重新安装它,并且当我导航回 Web URL 时,凭据仍然会被缓存。我发现清除凭据的唯一方法是关闭 iPad 并重新打开电源。
问题:如何以编程方式清除凭据?
所以我就此开了一个苹果“技术支持事件”。以下是他们的回答摘要: SFSafariViewController 在我的应用程序进程之外运行,为了确保安全,我的应用程序无法修改 SFSafariViewController 的状态。换句话说,我的应用程序无法清除 SFSafariViewController 存储的凭据。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)