NSURL Error Code 1022

So, the problem had to do with ATS (App Transport Security), a new feature in iOS 9 that checks the authenticity of a URL before connecting to it. As I am not concerned about the secure-ness of the website I'm connecting to, I disabled ATS entirely. This can be done by adding the following code to the app's info.plist file:

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

for swift4 add this in app's info.plist

<key>App Transport Security Settings</key>
<dict>
<key>Allow Arbitrary Loads</key>
<true/>
</dict>

or

go to app's info.plist

Right click and select Add Row and find App Transport Security Settings and click it. then again Right click on App Transport Security Settings and select Add Row then find and click Allow Arbitrary Loads and modify its value to YES.

Autocomplete when typing "App Transport...." or "Allow Arbitrary..." can be slow or nonexistent, so you can either wait it out or type it anyway and then click on "Value" side of list (to the right) and write YES (for Allow Arbitrary Loads). App Transport Security Settings won't have a "Value" until you add the Arbitrary Loads, then it will say "(1 item)"