Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURL Error Code 1022

I have an RSS reader app, that has a parser. It has worked well, up until iOS 9 beta. Whenever I try to load data, I get error code 1022. Here is my code for establishing a connection:

- (void)parseRssFeed:(NSString *)url withDelegate:(id)aDelegate {
[self setDelegate:aDelegate];

responseData = [NSMutableData data];
NSURL *baseURL = [NSURL URLWithString:url];


NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}

And the error handler:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSString * errorString = [NSString stringWithFormat:@"Unable to download XML data (Error code %i )", [error code]];

UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}

I'm not sure what changed between iOS 8 and 9, but for some reason the app no longer works. Any help would be greatly appreciated!

like image 782
Bryan Avatar asked Sep 11 '15 20:09

Bryan


2 Answers

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>
like image 95
Bryan Avatar answered Jan 04 '23 11:01

Bryan


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)"

like image 26
Ravi Kumar Avatar answered Jan 04 '23 10:01

Ravi Kumar