Objective-C
- 1 ответ
- 0 вопросов
1
Вклад в тег
dataTaskWithRequest
#import <AFNetworking.h>
NSString *urlString = @"https://api...";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *mutableURLRequest = [NSMutableURLRequest requestWithURL:url];
NSMutableData *requestBodyData = [NSMutableData data];
mutableURLRequest.HTTPBody = requestBodyData;
mutableURLRequest.HTTPMethod = @"POST";
NSString *accessToken = @"accessToken";
NSString *value = [NSString stringWithFormat:@"Bearer %@", accessToken];
[mutableURLRequest setValue:value forHTTPHeaderField:@"Authorization"];
[mutableURLRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[[AFHTTPSessionManager manager] dataTaskWithRequest:mutableURLRequest completionHandler:^(NSURLResponse * _Nonnull response,
id _Nullable responseObject,
NSError * _Nullable error) {
//We do not reach this code block !
// Save the incoming data to CoreData
completionHandler(UIBackgroundFetchResultNewData);
}];