简体   繁体   中英

afnetworking with iOS 9 sessions

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.

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM