Asynchronous Get Mode
1 //MARK:-Asynchronous Get Mode2 func asynchronousget ()3 {4 //Create a Nsurl object5var url:nsurl! = Nsurl (string:"http://m.weather.com.cn/data/101010100.html")6 7 //Create Request Object8var urlrequest:nsurlrequest = nsurlrequest (Url:url, CachePolicy:NSURLRequestCachePolicy.UseProtocolCachePolicy, timeOutInterval:Ten)9 Ten //connecting to a server Onevar connection = Nsurlconnection (Request:urlrequest,Delegate: Self) A } - - the //MARK:-nsurlconnectiondelegate:nsobjectprotocol { - func Connection (connection:nsurlconnection, Didfailwitherror error:nserror) - { - //request failed + } -Func Connectionshouldusecredentialstorage (connection:nsurlconnection)Bool + { A //connection should use certificate store at return true - } - func Connection (connection:nsurlconnection, Willsendrequestforauthenticationchallenge Challenge: Nsurlauthenticationchallenge) - { - //Send Request Verification - } inFunc connection (connection:nsurlconnection, Canauthenticateagainstprotectionspace protectionspace: Nsurlprotectionspace)Bool - { to //protected space that can be verified + return true - } the func Connection (connection:nsurlconnection, Didreceiveauthenticationchallenge Challenge: Nsurlauthenticationchallenge) * { $ //Get CertifiedPanax Notoginseng } - func Connection (connection:nsurlconnection, Didcancelauthenticationchallenge Challenge: Nsurlauthenticationchallenge) the { + //Cancel Certification A}
iOS Development--Network Programming Swift & (iv) asynchronous get mode