IOS 9 NSURLConnection deprecated

前端 未结 2 1282
春和景丽
春和景丽 2021-01-19 02:33

I upgraded to IOS9 xcode, and I do not work the method of obtaining answer of my webservice , this part NSData *urlData=[NSURLConnection sendSynchronousRequest:request retur

2条回答
  •  长情又很酷
    2021-01-19 03:12

    Your actual problem is not NSURLConnection usage ios9 will handle it even if it is depricated also , here the problem with http request you are using from ios9 apple discourages the use of HTTP request as part of the App Transport Security (ATS)

    From Apple documentation:

    "App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.

    If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible. In addition, your communication through higher-level APIs needs to be encrypted using TLS version 1.2 with forward secrecy.

    If you try to make a connection that doesn't follow this requirement, an error is thrown. If your app needs to make a request to an insecure domain, you have to specify this domain in your app's Info.plist file."

    You can bypass this by adding this key to your info.plist of the project

    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
    
    

    stack overflow link and blog reference link ios9 ATS

提交回复
热议问题