71 lines
2.2 KiB
Objective-C
71 lines
2.2 KiB
Objective-C
//
|
|
// GiGaNetManager.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/8/15.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "GiGaNetManager.h"
|
|
#import "AFNetworking.h"
|
|
#import "GiGaServerConfig.h"
|
|
@interface GiGaNetManager()
|
|
|
|
@end
|
|
|
|
@implementation GiGaNetManager
|
|
|
|
+ (GiGaNetManager *)shareInstance{
|
|
static GiGaNetManager *instance = nil;
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
instance = [[self alloc] init];
|
|
});
|
|
return instance;
|
|
}
|
|
|
|
+ (void)request:(GiGaAPIRequest *)api{
|
|
|
|
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
NSURL *baseUrl = [NSURL URLWithString:[GiGaServerConfig getMainUrl]];
|
|
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:configuration];
|
|
|
|
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
|
switch (api.requestType) {
|
|
case kRequestTypeGet:
|
|
|
|
{
|
|
[manager GET:api.fullUrl parameters:api.params progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
|
|
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
NSDictionary *outDic = (NSDictionary *)responseObject;
|
|
[api callBackFinishedWithDictionary:outDic];
|
|
|
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
[api callBackFailed:error];
|
|
}];
|
|
|
|
}
|
|
break;
|
|
|
|
case kRequestTypePost:
|
|
{
|
|
[manager POST:api.fullUrl parameters:api.params progress:^(NSProgress * _Nonnull uploadProgress) {
|
|
|
|
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
NSDictionary *outDic = (NSDictionary *)responseObject;
|
|
[api callBackFinishedWithDictionary:outDic];
|
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
[api callBackFailed:error];
|
|
}];
|
|
}
|
|
break;
|
|
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
@end
|