Madhu
Madhu

Reputation: 929

How to pass an Authorization token for AFNetworking 2.0 as it is deprecated

I'm Currently working on a project where I'm using AFNetworking 2.0 library to GET and POST the data to and from server.In some cases i wanted to pass a token value as header type for the request with AFHTTPRequestOperationManager. So far this is what i found

[manager.requestSerializer setAuthorizationHeaderFieldWithToken:TOKEN_VALUE];

but it is deprecated in version 2.0, and i also learned in version AFNetWorking 2.2.1 it is not deprecated. But i couldn't find the library with version 2.2.1 to download it. Please help me out if there is any other way that i can set token as my header for AFHTTPRequestOperationManager. And also any link to download the AFNetworking latest version library.

Upvotes: 3

Views: 2331

Answers (1)

Jonathan Yeong
Jonathan Yeong

Reputation: 563

This is the deprecation message in the AFNetworking docs:

This method has been deprecated. Use setValue:forHTTPHeaderField: instead. (Deprecated: This method has been deprecated. Use -setValue:forHTTPHeaderField: instead.)

The docs for this method setValue:forHTTPHeaderField: can be found here. To set a token as your header with the AFNetworking method setValue:forHTTPHeaderField: try:

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager manager] initWithBaseURL:@"http://someurl.com"];

[manager.requestSerializer setValue:@"Token token=token_name" forHTTPHeaderField:@"Authorization"];

Upvotes: 3

Related Questions