Reputation: 2906
I am using AFNetworking 2. Everything working fine. But here I am using singleton method. I want to change the header value when I logout and login again. But AFNetworking header value is not changing. It always keeping previous value. I put the break point inside the singleton method. It is going to first time only. After that it is not going.
This is my code.
+ (ContactSync *)sharedAPI
{
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedApi = [[self alloc] initWithBaseURL:[NSURL URLWithString:APIURL_BASEURL] ];
_sharedApi.requestSerializer = [AFHTTPRequestSerializer serializer];
_sharedApi.requestSerializer = [AFJSONRequestSerializer serializer];
[_sharedApi.requestSerializer setValue:[CommonUtils loginToken] forHTTPHeaderField:@"X-Auth-Token"];
NSLog(@"++++++++++++%@", [CommonUtils loginToken]);
_sharedApi.responseSerializer = [AFJSONResponseSerializer serializer];
});
return _sharedApi;
}
Here I used NSLog print the value. But it is only printing one time. Please help me.
Upvotes: 0
Views: 268
Reputation: 16825
You are using dispatch_once
, therefore the block is only executed once. You have to get the ContactSync
class object, and change the value on the request serializer.
[[ContactSync sharedAPI].requestSerializer setValue:[CommonUtils loginToken] forHTTPHeaderField:@"X-Auth-Token"];
Upvotes: 1