afnetworking with iOS 9 sessions

449 Views Asked by At

I have that big project it's for some websites so I made a subclass from AFHTTPSessionManager as service class, everything was working fine till iOS 9 released, then login doesn't work I checked I get token and everything but I can't use them I mean when I request to see my cars for example server sends me that I am not logged in. I used those keys for server exception but didnt work. I am sorry for that lame question.

2

There are 2 best solutions below

0
On BEST ANSWER

I solved my problem by adding this method to my subclass of AFHTTPSessionManager

- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLResponse *, id, NSError *))completionHandler{

NSMutableURLRequest *req = (NSMutableURLRequest *)request;
[req setValue:headerToken forHTTPHeaderField:@"header"];

return [super dataTaskWithRequest:req completionHandler:completionHandler];}

so it's like every time I create data task I will just force it to send the header.

0
On

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.

For a quick hack you can do the following,

Add this to the Info.plist:

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