我正在使用Swift 2中的SFSafariViewController在iPad Air 2上显示带有IOS9.1 (13B143)的网页。每个网页都需要用户的凭据。但是,当用户按下注销按钮时,我需要清除这些凭据。我尝试使用以下方法:
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()但不起作用。事实上,“删除凭据”和“删除COOKIE”从未被打印过。此外,我可以从iPad中完全删除应用程序并重新安装它,当我导航回web url时,凭证仍然被缓存。我发现清除凭据的唯一方法是关闭iPad并重新启动它。
问:如何以编程方式清除凭据?
发布于 2015-12-07 14:35:50
因此,我在这件事上开了一个苹果公司的“技术支持事件”。以下是他们回答的总结: SFSafariViewController运行在我的应用程序进程之外,为了安全起见,我的应用程序不能修改SFSafariViewController的状态。换句话说,我的应用程序不能清除SFSafariViewController存储的凭据。
https://stackoverflow.com/questions/34079135
复制相似问题