我想知道是否可以从iOS应用程序以编程方式访问存储在SharePoint库中的图像。 将其定义为URL。在URLSessionDelegate中,身份验证方法为NSURLAuthenticationMethodServerTrust和有效凭据。
在完成处理程序中,我收到错误为零。 但响应说 - 访问+拒绝。+前+开+文件+中+此+位置%2c +你+必须+第一+浏览+到+ +网站+网站+ + +选择+ +选项+到+登录+自动
是否真的可以通过这种方式从sharepoint访问图像,而无需使用图形API?
答案 0 :(得分:0)
好像你没有正确认证。这是swift中的URLSessionDelegate函数,它检查挑战中的身份验证方法。对于sharepoint站点,它通常应该是NSURLAuthenticationMethodNTLM。
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard challenge.previousFailureCount == 0 else {
print("too many failures")
challenge.sender?.cancel(challenge)
completionHandler(.cancelAuthenticationChallenge, nil)
return
}
guard challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM else {
print("unknown authentication method \(challenge.protectionSpace.authenticationMethod)")
challenge.sender?.cancel(challenge)
completionHandler(.cancelAuthenticationChallenge, nil)
return
}
guard self.doesHaveCredentials() else {
challenge.sender?.cancel(challenge)
completionHandler(.cancelAuthenticationChallenge, nil)
DispatchQueue.main.async {
print("Userdata not set")
};
return
}
let credentials = URLCredential(user: self.username!, password: self.password!, persistence: .forSession)
challenge.sender?.use(credentials, for: challenge)
completionHandler(.useCredential, credentials)
}
这是从https://gist.github.com/stevenschobert/f374c999e5cba6ccf09653b846967c83获取的,其中有一个使用swift进行NTLM身份验证的好例子。