ast*_*003 6 safari ipad ios swift sfsafariviewcontroller
我在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()
Run Code Online (Sandbox Code Playgroud)
但它不起作用.实际上,"DELETING CREDENTIAL"和"DELETING COOKIE"永远不会被打印出来.此外,我可以完全删除iPad上的应用程序并重新安装它,当我导航回网址时,凭据仍然被缓存.我发现清除凭据的唯一方法是关闭iPad并重新启动它.
问题:如何以编程方式清除凭据?
所以我就此开了一个Apple"技术支持事件".以下是他们答案的摘要:SFSafariViewController在我的App的进程之外运行,为了安全,我的App无法修改SFSafariViewController的状态.换句话说,我的应用程序无法清除SFSafariViewController存储的凭据.
| 归档时间: |
|
| 查看次数: |
3509 次 |
| 最近记录: |