Ios 如何清除SFSafariViewController凭据?

Ios 如何清除SFSafariViewController凭据?,ios,swift,ipad,safari,sfsafariviewcontroller,Ios,Swift,Ipad,Safari,Sfsafariviewcontroller,我正在使用Swift 2中的SFSafariViewController在ios 9.1(13B143)的iPad Air 2上显示网页。每个网页都需要用户提供凭据。但是,当用户按下注销按钮时,我需要清除这些凭据。我尝试使用以下方法: let allCreds = NSURLCredentialStorage.sharedCredentialStorage().allCredentials for (protectionSpace, userCredsDict) in allCred

我正在使用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()
但它不起作用。事实上,“删除凭证”和“删除COOKIE”永远不会打印出来。此外,我可以从iPad上完全删除该应用程序并重新安装,当我导航回web url时,凭据仍然会被缓存。我发现清除凭据的唯一方法是关闭iPad并重新开机


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

因此,我就此打开了一个苹果“技术支持事件”。以下是他们回答的摘要:SFSafariViewController在我的应用程序进程之外运行,为了安全起见,我的应用程序无法修改SFSafariViewController的状态。换句话说,我的应用程序无法清除SFSafariViewController存储的凭据。

谢谢您的分享。我在找完全一样的东西。