NSURLConnection finished with error - code -1022

前端 未结 5 641
南笙
南笙 2020-12-15 06:47

Guys i try to learn webview it can\'t load give me error like:

NSURLConnection finished with error - code -1022

- (voi         


        
相关标签:
5条回答
  • 2020-12-15 07:27

    Few silly things but give a try as below:

    1. First, you can try to check the issue on the simulator i.e run the app in the simulator and check whether still there is an issue.

    2. In-network class or where your API call function check whether this is implemented

      request.allHTTPHeaderFields = ["Content-Type" : "application/json"]

    3. Right-click on info.plist file. select open as source code.

    check and find below whether lines are present

    <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    </dict>
    

    if not present add above lines just before /dict:

    1. Also, check if you are URL is from the local server and you are switching to the different live URL.

    2. Check the internet connection of the device.

    0 讨论(0)
  • 2020-12-15 07:39

    To give an answer on your question we need to see full logs. But I guess the problem in the App Transport Security. Since iOS 9 all connection should be done with https and the destination url should be backed with TLS version greater or equal 1.2, until you'll not specify exceptions in info.plist file in App Transport security section. Also you can "Allow Arbitrary Loads" for all connections, but this way isn't preferred. You can read more details about this here https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html (in the NSAppTransportSecurity section)

    0 讨论(0)
  • 2020-12-15 07:44

    I think it is about App Transport Security.Because your url is not https.Try to change like this in the info.plist file

    <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    </dict>
    
    0 讨论(0)
  • 2020-12-15 07:45

    You are getting this error because you are not using https url. To fix follow below steps:

    • Right click on info.plist file.
    • Open As Source code.
    • Add below line just before /dict:

      <key>NSAppTransportSecurity</key>
      <dict>
          <key>NSAllowsArbitraryLoads</key>
          <true/>
      </dict>
      
    0 讨论(0)
  • 2020-12-15 07:48

    I was having a similar issue,

    NSURLConnection finished with error - code -1200
    

    I was trying to reach a blocked port in my company. Changing the port let me connect normally.

    As pointed out below, disabling Firewall could also solve the issue.

    0 讨论(0)
提交回复
热议问题