-(void)Start
{
NSString *stringURL = [NSString stringWithFormat:@"url"];
NSString* webStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"GET" URLString:webStringURL parameters:nil error:nil];
req.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[MBProgressHUD showHUDAddedTo:self.view animated:true];
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error)
{
if (!error)
{
NSLog(@"Reply JSON: %@", responseObject);
if ([responseObject isKindOfClass:[NSArray class]])
{
arrResult=[[NSMutableArray alloc]init];
for (NSMutableDictionary *dic in responseObject)
{
[arrResult addObject:dic];
}
}
}
else
{
NSLog(@"Error: %@, %@, %@", error, response, responseObject);
}
}] resume];
}
No comments:
Post a Comment