如何清除SFSafariViewController凭据? [英] How to clear SFSafariViewController credentials?

查看:282
本文介绍了如何清除SFSafariViewController凭据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Swift 2中使用SFSafariViewController在带有ios 9.1(13B143)的iPad Air 2上显示网页。每个网页都需要用户提供的凭据。但是,当用户按下注销按钮时,我需要清除这些凭据。我尝试过使用以下内容:

I'm using SFSafariViewController in Swift 2 to display web pages on an iPad Air 2 with ios 9.1 (13B143). Each of the web pages requires credentials from the user. However, when the user presses a logout button, I need to clear those credentials. I've tried using the following:

  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上的应用程序并重新安装它,当我导航回网址时,凭据仍然被缓存。我发现清除凭据的唯一方法是关闭iPad并重新启动它。

but it doesn't work. In fact, "DELETING CREDENTIAL" and "DELETING COOKIE" never gets printed. Moreover, I can entirely delete the app off of the iPad and reinstall it and the credentials are still cached when I navigate back to the web url. The only way I have found to clear the credentials is to shut down the iPad and power it back on.

问题:如何以编程方式清除凭据?

Question: How can I programmatically clear the credentials?

推荐答案

所以我就此开了一个Apple'技术支持事件'。以下是他们答案的摘要:SFSafariViewController在我的App的进程之外运行,为了安全,我的App无法修改SFSafariViewController的状态。换句话说,我的应用程序无法清除SFSafariViewController存储的凭据。

So I opened an Apple 'Technical Support Incident' on this. The following is summary of their answer: SFSafariViewController runs outside of my App's process and in order to be secure my App can not modify SFSafariViewController's state. In other words, my App can not clear credentials stored by SFSafariViewController.

这篇关于如何清除SFSafariViewController凭据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆