This is the answer I get from API:
- (void)postRequestWithHeader:(NSString *)url
parameters:(NSDictionary *)parameters
completionHandler:(void (^)(NSDictionary *data, NSError *))completionHandler
{
NSString *URLString = [NSString stringWithFormat:@"%@%@", baseURL, url];
NSMutableURLRequest *request= [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:URLString parameters:parameters error:nil];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSString *session =[[LocalDataBase sharedDataBase]userDataObjectForKey:@"session"];
[request setValue:session forHTTPHeaderField:@"session"];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSDictionary *backParam = [[AFHTTPResponseSerializer serializer] responseObjectForResponse:responseObject data:responseObject error:nil];
if (error) {
NSLog(@"Error: %@", error);
completionHandler(nil, error);
} else {
if ([responseObject isKindOfClass:[NSArray class]]) {
NSLog(@"response is in array");
}else {
NSLog(@"%@ %@", response, responseObject);
completionHandler(backParam, nil);
}
;}
}];
[dataTask resume];
}
-(void) requestForPosts:(void (^)(NSError *error))completionHandler
{
[self postRequestWithHeader:@"posts/list"
parameters:nil
completionHandler:^(NSDictionary *data, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
completionHandler(error);
} else {
NSLog(data);
// [[LocalDataBase sharedDataBase] saveUserData:data];
completionHandler(nil);
}
}];
}
This is code i use to send request for API and then i get response and check if it is array, but i don't know what tot do after this I need to get this response and put into table view/ I hope someone will help me)