HTTPS request on old iphone 3g

爱⌒轻易说出口 提交于 2020-01-14 10:23:12

问题


Anyone else having issues with getting a https request working on the old iphone.

From connection did fail with error the error message is as follows.

ERROR with theConnection:Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.ourwesbite.co.uk” which could put your confidential information at risk."

The "ourwebsite" has a valid certificate and also this problem does not arise in any new iphone/ipod touch or ipads just the oldest iphones.

This is affecting my login from working by throwing a connection error after user clicks ok to the connection error alert the login process runs through fine. But the problem is its affecting the UI after the login.

So pretty much want to know if anyone else is having issues like this with the old iphone. There is no problem with my code as it works perfectly fine on simulator & ipad/4gen ipod touch.

Thanks


回答1:


We had this error and the iPhone 3g in question had an incorrect date and time set. This meant all SSL transactions would fail.

We assumed that this iOS bug is an apple problem not ours and so hacking the SSL certificate to be ignored is not the solution!




回答2:


Ok so even tho the certificate is valid it will throws the error. So using the following delegate method for NSURLConnection solved this problem.

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{

it gets called when there is a challenge to the authentication. The the following bit of code allow's it to continue with the https connection.

[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

And then that allows the connection through if it feels it is untrusted



来源:https://stackoverflow.com/questions/4861103/https-request-on-old-iphone-3g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!