add files apis
This commit is contained in:
@@ -36,12 +36,13 @@
|
||||
if (self.viewControllers.count > 1 ) {
|
||||
//自定义返回按钮
|
||||
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[backBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
|
||||
backBtn.backgroundColor = [UIColor redColor];
|
||||
backBtn.frame = CGRectMake(0, 0, 40, 40);
|
||||
[backBtn setImage:[UIImage imageNamed:@"btn_moment_back"] forState:UIControlStateNormal];
|
||||
[backBtn setImageEdgeInsets:UIEdgeInsetsMake(0,-14, 0, 14)];
|
||||
//backBtn.backgroundColor = [UIColor redColor];
|
||||
[backBtn addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
|
||||
viewController.navigationItem.leftBarButtonItem = backItem;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,14 +56,4 @@
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||||
// Get the new view controller using [segue destinationViewController].
|
||||
// Pass the selected object to the new view controller.
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
[self.view addSubview:_tableView];
|
||||
[self testNetworkStatus];
|
||||
//[self testNetworkStatus];
|
||||
}
|
||||
|
||||
-(void)addNavTitile:(NSString *)title{
|
||||
|
||||
@@ -36,12 +36,12 @@
|
||||
NSURL *imageUrl = [[NSBundle mainBundle] URLForResource:@"MaskTime" withExtension:@"png"];
|
||||
UNNotificationAttachment *attach = [UNNotificationAttachment attachmentWithIdentifier:@"photo" URL:imageUrl options:nil error:nil];
|
||||
|
||||
NSURL *audioUrl = [[NSBundle mainBundle] URLForResource:@"4481" withExtension:@"wav"];
|
||||
UNNotificationAttachment *attachAudio = [UNNotificationAttachment attachmentWithIdentifier:@"audio" URL:audioUrl options:nil error:nil];
|
||||
// NSURL *audioUrl = [[NSBundle mainBundle] URLForResource:@"4481" withExtension:@"wav"];
|
||||
// UNNotificationAttachment *attachAudio = [UNNotificationAttachment attachmentWithIdentifier:@"audio" URL:audioUrl options:nil error:nil];
|
||||
|
||||
NSURL *vedioUrl = [[NSBundle mainBundle] URLForResource:@"emojizone" withExtension:@"mp4"];
|
||||
UNNotificationAttachment *vedioAudio = [UNNotificationAttachment attachmentWithIdentifier:@"vedio" URL:vedioUrl options:nil error:nil];
|
||||
content.attachments = @[attachAudio];
|
||||
// NSURL *vedioUrl = [[NSBundle mainBundle] URLForResource:@"emojizone" withExtension:@"mp4"];
|
||||
// UNNotificationAttachment *vedioAudio = [UNNotificationAttachment attachmentWithIdentifier:@"vedio" URL:vedioUrl options:nil error:nil];
|
||||
content.attachments = @[attach];
|
||||
|
||||
//延迟通知 第一个参数是重复的时间间隔,最小60s,第二个参数是是否重复。
|
||||
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// GiGaAPIRequest.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/15.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "GiGaAPIResult.h"
|
||||
@class GiGaAPIRequest;
|
||||
#define DEFALUT_APIREQUEST_TIMEOUT 20
|
||||
|
||||
typedef enum GiGaRequestType {
|
||||
kRequestTypeGet,
|
||||
kRequestTypePost,
|
||||
kRequestTypeUpload,
|
||||
kRequestTypeMultiUpload
|
||||
}GiGaRequestTyp;
|
||||
|
||||
typedef enum ApiResultFormat {
|
||||
kApiResultJson,
|
||||
kApiResultXml,
|
||||
}ApiResultFormat;
|
||||
|
||||
@protocol GiGaApiRquestDelegate<NSObject>
|
||||
@optional
|
||||
|
||||
- (void)serverApiFinishedSuccessed:(GiGaAPIRequest *)api result:(GiGaAPIResult *)result;
|
||||
- (void)serverApiRequestFailed:(GiGaAPIRequest *)api error:(NSError *)error;
|
||||
- (void)serverApiFinishedFailed:(GiGaAPIRequest *)api result:(GiGaAPIResult *)result;
|
||||
|
||||
@end
|
||||
|
||||
@interface GiGaAPIRequest : NSObject
|
||||
|
||||
#pragma mark - porperty
|
||||
/** 请求类型 */
|
||||
@property (nonatomic, readonly) GiGaRequestTyp requestType;
|
||||
/** 请求返回的格式 */
|
||||
@property (nonatomic, readonly) ApiResultFormat resultFormat;
|
||||
/** 请求超时时间 */
|
||||
@property (nonatomic, readonly) NSTimeInterval timeout;
|
||||
/** 服务器地址 */
|
||||
@property (nonatomic, readonly) NSString *serviceUrl;
|
||||
/** 请求路径 */
|
||||
@property (nonatomic, readonly) NSString *fullUrl;
|
||||
/** 代理 */
|
||||
@property (nonatomic, weak) id<GiGaApiRquestDelegate> delegate;
|
||||
/** 请求参数数组 */
|
||||
@property (nonatomic, strong) NSMutableArray *params;
|
||||
|
||||
#pragma mark - Method
|
||||
- (id)initWithDelegate:(id<GiGaApiRquestDelegate>)delegate;
|
||||
/**
|
||||
* 拼接公共参数
|
||||
*/
|
||||
- (void)appendBaseParams;
|
||||
|
||||
#pragma mark - APIRequestDelegate
|
||||
/**
|
||||
* 返回数据调用方法
|
||||
*/
|
||||
- (void)callBackFinishedWithDictionary:(NSDictionary *)dic;
|
||||
/**
|
||||
* 返回数据错误
|
||||
*/
|
||||
- (void)callBackFailed:(NSError *)error;
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// GiGaAPIRequest.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/15.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaAPIRequest.h"
|
||||
#import "GiGaServerConfig.h"
|
||||
@implementation GiGaAPIRequest
|
||||
|
||||
- (id)initWithDelegate:(id<GiGaApiRquestDelegate>)delegate
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.params = [NSMutableArray array];
|
||||
self.delegate = delegate;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
//默认Get访问
|
||||
- (GiGaRequestTyp)requestType
|
||||
{
|
||||
return kRequestTypeGet;
|
||||
}
|
||||
|
||||
//默认超时时间
|
||||
- (NSTimeInterval)timeout
|
||||
{
|
||||
return DEFALUT_APIREQUEST_TIMEOUT;
|
||||
}
|
||||
|
||||
//服务器地址
|
||||
-(NSString *)serviceUrl{
|
||||
return [GiGaServerConfig getMainUrl];
|
||||
}
|
||||
|
||||
/** 拼接的请求地址 */
|
||||
|
||||
//
|
||||
- (NSString *)fullUrl
|
||||
{
|
||||
// 服务器地址 和 接口名
|
||||
NSString *url = [NSString stringWithFormat:@"%@",self.serviceUrl];
|
||||
|
||||
return url;
|
||||
}
|
||||
// 数据请求完成的 回调
|
||||
- (void)callBackFinishedWithDictionary:(NSDictionary *)dic
|
||||
{
|
||||
// 处理 responseObject
|
||||
GiGaAPIResult *resu = [[GiGaAPIResult alloc] initWithDictionary:dic];
|
||||
// error ID = 0
|
||||
if (resu.success) {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(serverApiFinishedSuccessed: result:)]) {
|
||||
//
|
||||
[self.delegate serverApiFinishedSuccessed:self result:resu];
|
||||
}
|
||||
// error ID = 1
|
||||
} else {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(serverApiFinishedFailed:result:)]) {
|
||||
[self.delegate serverApiFinishedFailed:self result:resu];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据请求失败的回调
|
||||
- (void)callBackFailed:(NSError *)error
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(serverApiRequestFailed:error:)]) {
|
||||
[self.delegate serverApiRequestFailed:self error:error];
|
||||
}
|
||||
}
|
||||
|
||||
// 拼接的基本参数
|
||||
- (void)appendBaseParams
|
||||
{
|
||||
|
||||
}
|
||||
@end
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
/** 提示信息 */
|
||||
@property (nonatomic, copy) NSString *message;
|
||||
/** 请求状态 */
|
||||
@property (nonatomic, assign) NSInteger status;
|
||||
/** 状态码 */
|
||||
@property (nonatomic, assign) NSInteger code;
|
||||
/** 请求是否成功 */
|
||||
@property (nonatomic, readonly) BOOL success;
|
||||
/** 接收数据的字典 */
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
-(BOOL)success{
|
||||
|
||||
return self.status == 0;
|
||||
return self.code == 0? YES : NO;
|
||||
|
||||
}
|
||||
|
||||
@@ -21,21 +21,21 @@
|
||||
if (self = [super init]) {
|
||||
@try {
|
||||
if (dic && ![dic isKindOfClass:[NSNull class]]) {
|
||||
self.status = [[dic objectForKey:@"errorcode"] intValue];//待定
|
||||
self.message = [dic objectForKey:@""];//待定
|
||||
self.code = [[dic objectForKey:@"code"] integerValue];
|
||||
self.message = [dic objectForKey:@"msg"];
|
||||
NSDictionary *data = [[dic objectForKey:@"result"] objectForKey:@"data"];
|
||||
self.dic = data;
|
||||
|
||||
}else{
|
||||
self.message = @"网络错误";
|
||||
self.message = @"请求异常";
|
||||
self.dic = nil;
|
||||
self.status = 1;
|
||||
self.code = -1;
|
||||
}
|
||||
|
||||
}
|
||||
@catch(NSException *exception) {
|
||||
self.dic = dic;
|
||||
self.status = 0;
|
||||
self.code = -1;
|
||||
|
||||
}
|
||||
@finally {
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// GiGaBaseAPiRequest.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/29.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "GiGaAPIResult.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, GIGARequestStatus) {
|
||||
NotAvailable = 1, //不可用
|
||||
RequestSuccess = 2, //请求成功
|
||||
RequestFailed = 4, //请求失败
|
||||
RequestLocalData = 8, //本地请求
|
||||
RequestNoMoreContent = 16, //没有更多数据
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, GIGARequestNetStatus) {
|
||||
|
||||
NetStatusWifi = 1,
|
||||
NetStatusWWAN = 2,
|
||||
NetStatusUnKown= 4,//不可用
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, RequestMethod) {
|
||||
RequestPostMethod = 1, //post 请求
|
||||
RequestGetMethod = 2, //get 请求
|
||||
RequestPutMethod = 3, //put 请求
|
||||
RequestDelMethod = 4, //del 请求
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger ,GiGAErrorCode){
|
||||
GiGAErrorCode_SUCCESS = 0,//成功
|
||||
GiGAErrorCode_USER_EXIST = 500,//用户已存在
|
||||
|
||||
};
|
||||
|
||||
@class GiGaBaseAPiRequest;
|
||||
|
||||
typedef void (^GiGaRequestResultBlock)(GiGaAPIResult *result);
|
||||
|
||||
@interface GiGaBaseAPiRequest : NSObject
|
||||
|
||||
#pragma mark - porperty
|
||||
|
||||
@property (nonatomic,assign) GIGARequestNetStatus statu;
|
||||
|
||||
//@property (nonatomic, copy) GIGARequestSuccessBlock successBlock;
|
||||
//@property (nonatomic, copy) GIGARequetFailBlock failBlock;
|
||||
@property (nonatomic,copy) GiGaRequestResultBlock blockresult;
|
||||
|
||||
/** 请求类型 */
|
||||
@property (nonatomic, assign) RequestMethod requestMethod;
|
||||
/** 请求超时时间 */
|
||||
@property (nonatomic, readonly) NSTimeInterval timeout;
|
||||
/** 服务器地址 */
|
||||
@property (nonatomic, readonly) NSString *serviceUrl;
|
||||
/** 请求路径 */
|
||||
@property (nonatomic, copy) NSString *fullUrl;
|
||||
|
||||
/** 请求参数 */
|
||||
@property (nonatomic, strong) NSMutableDictionary *params;
|
||||
|
||||
/**
|
||||
* 请求得到的全部数据
|
||||
*/
|
||||
@property (strong, nonatomic) NSDictionary *resultDict;
|
||||
|
||||
@property (strong, nonatomic) NSDictionary *responseHeaderFields;
|
||||
|
||||
@property (nonatomic, assign) BOOL needToken; // 是否需要带上token
|
||||
|
||||
/**
|
||||
* 检查网络
|
||||
*/
|
||||
- (void)checkNetwork;
|
||||
|
||||
|
||||
/**
|
||||
发起请求
|
||||
|
||||
@param result 。
|
||||
*/
|
||||
- (void)requstDataWithResult:(GiGaRequestResultBlock)result;
|
||||
|
||||
|
||||
/**
|
||||
* 发起本地存储数据请求
|
||||
*
|
||||
* @param success 成功block
|
||||
* @param failure 失败block
|
||||
*/
|
||||
//- (void)loadLocalDataAsyncWithSuccess:(GIGARequestSuccessBlock)success
|
||||
// failure:(GIGARequetFailBlock)failure;
|
||||
/**
|
||||
* 分析错误信息
|
||||
*
|
||||
* @param requestDict 服务器返回数据
|
||||
* @param error error信息
|
||||
*/
|
||||
- (void)analyseResponseInfo:(NSDictionary *)requestDict error:(NSError *)error;
|
||||
|
||||
- (void)analyseResponseInfo:(NSDictionary *)requestDict
|
||||
headerFileds:(NSDictionary *)headerFields
|
||||
error:(NSError *)error;
|
||||
|
||||
|
||||
/**
|
||||
API convenience constructor
|
||||
@param path request path
|
||||
@param method method
|
||||
@param parms parms
|
||||
@return model
|
||||
*/
|
||||
+ (instancetype)initWithRequestPath:(NSString *)path
|
||||
method:(RequestMethod)method
|
||||
parms:(NSDictionary *)parms;
|
||||
|
||||
+ (instancetype)initWithRequestAbsoluteURLString:(NSString *)absoluteString
|
||||
method:(RequestMethod)method
|
||||
parms:(NSDictionary *)parms;
|
||||
|
||||
//+ (instancetype)uploadImage:(NSString *)url
|
||||
// imgData:(NSData *)imgData
|
||||
// parms:(NSDictionary *)parms
|
||||
// success:(GIGARequestSuccessBlock)success
|
||||
// failure:(GIGARequetFailBlock)failure;
|
||||
|
||||
//+ (NSString *)resizeImageUrl:(NSString *)originImageUrl
|
||||
// size:(CGSize)size;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,163 @@
|
||||
//
|
||||
// GiGaBaseAPiRequest.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/8/29.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GiGaBaseAPiRequest.h"
|
||||
#import "GiGaServerConfig.h"
|
||||
#import <JSONModel/JSONModel.h>
|
||||
#import "GiGaNetManager.h"
|
||||
|
||||
@implementation GiGaBaseAPiRequest
|
||||
|
||||
- (NSString *)serviceUrl
|
||||
{
|
||||
return [GiGaServerConfig getMainUrl];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_needToken = NO;
|
||||
self.requestMethod = RequestGetMethod;
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+(instancetype)initWithRequestPath:(NSString *)path method:(RequestMethod)method parms:(NSDictionary *)parms
|
||||
{
|
||||
NSString *absoluteURLString = [NSString stringWithFormat:@"%@%@", [GiGaServerConfig getMainUrl], path];
|
||||
return [self initWithRequestAbsoluteURLString:absoluteURLString
|
||||
method:method
|
||||
parms:parms];
|
||||
}
|
||||
|
||||
+ (instancetype)initWithRequestAbsoluteURLString:(NSString *)absoluteString
|
||||
method:(RequestMethod)method
|
||||
parms:(NSDictionary *)parms
|
||||
{
|
||||
GiGaBaseAPiRequest *request = [[self alloc] init];
|
||||
request.fullUrl = absoluteString;
|
||||
request.requestMethod = method;
|
||||
|
||||
[request buildRequestDictWithDepedency:parms];
|
||||
return request;
|
||||
}
|
||||
|
||||
+ (NSArray *)mergeOriginalArray:(NSArray *)orgArr withOtherArray:(NSArray *)otherArr;
|
||||
{
|
||||
if (otherArr.count == 0) {
|
||||
return orgArr;
|
||||
}
|
||||
|
||||
NSMutableArray *array = [NSMutableArray arrayWithArray:orgArr];
|
||||
for (int i = 0; i < otherArr.count; i++) {
|
||||
id object = [otherArr objectAtIndex:i];
|
||||
if (!orgArr || [orgArr indexOfObject:object] == NSNotFound) {
|
||||
[array addObject:object];
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
- (NSMutableDictionary *)buildRequestDict
|
||||
{
|
||||
if (!_params) {
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||
_params = dict;
|
||||
}
|
||||
return _params;
|
||||
}
|
||||
- (NSMutableDictionary *)buildRequestDictWithDepedency:(NSDictionary *)dict
|
||||
{
|
||||
self.params = dict.mutableCopy;
|
||||
return self.params;
|
||||
}
|
||||
|
||||
- (void)requstDataWithResult:(GiGaRequestResultBlock)result
|
||||
{
|
||||
self.blockresult = result;
|
||||
[self checkNetwork];
|
||||
if (self.statu == NetStatusUnKown) {
|
||||
return;
|
||||
}
|
||||
NSLog(@" %@", _fullUrl);
|
||||
// NSMutableDictionary *postDict = [self buildRequestDict];
|
||||
|
||||
[GiGaNetManager requestMethod:self.requestMethod Url:self.fullUrl params:self.params responseBlock:^(NSDictionary *responseDict, NSDictionary *responseHeaderFields, NSError *error) {
|
||||
|
||||
[self analyseResponseInfo:responseDict headerFileds:responseHeaderFields error:error];
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)analyseResponseInfo:(NSDictionary *)responseData error:(NSError *)error
|
||||
{
|
||||
[self analyseResponseInfo:responseData
|
||||
headerFileds:nil
|
||||
error:error];
|
||||
}
|
||||
|
||||
- (void)analyseResponseInfo:(NSDictionary *)responseData headerFileds:(NSDictionary *)headerFields error:(NSError *)error
|
||||
{
|
||||
self.responseHeaderFields = headerFields;
|
||||
NSString *token = headerFields[@"access-token"];
|
||||
if (token && token.length > 0) {
|
||||
//更新token
|
||||
//[FFBMSConfig shareInstance].token = token;
|
||||
}
|
||||
|
||||
GILog(@"headerFileds%@",headerFields);
|
||||
if (error) {
|
||||
GILog(@"err:%@",error.localizedDescription);
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"请求错误" duration:1 position:CSToastPositionCenter];
|
||||
self.blockresult(nil);
|
||||
return;
|
||||
}
|
||||
|
||||
self.resultDict =responseData;
|
||||
GiGaAPIResult *res = [[GiGaAPIResult alloc] initWithDictionary:responseData];
|
||||
if (self.blockresult) {
|
||||
self.blockresult(res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)checkNetwork{
|
||||
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
|
||||
[manager startMonitoring];
|
||||
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||
|
||||
switch (status) {
|
||||
case AFNetworkReachabilityStatusReachableViaWWAN:
|
||||
{
|
||||
GILog(@"2/3/4G");
|
||||
self.statu = NetStatusWWAN;
|
||||
}
|
||||
break;
|
||||
case AFNetworkReachabilityStatusReachableViaWiFi:
|
||||
{
|
||||
GILog(@"WiFi");
|
||||
self.statu = NetStatusWifi;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:@"网络异常" duration:1.0 position:CSToastPositionCenter];
|
||||
self.statu = NetStatusUnKown;
|
||||
GILog(@"Unkown Net");
|
||||
break;
|
||||
}
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -7,11 +7,18 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "GiGaAPIRequest.h"
|
||||
@interface GiGaNetManager : NSObject
|
||||
+(GiGaNetManager *)shareInstance;
|
||||
+(void)request:(GiGaAPIRequest*)api;
|
||||
#import "GiGaBaseAPiRequest.h"
|
||||
|
||||
typedef void (^responseBlock)(NSDictionary *responseDict, NSDictionary *responseHeaderFields, NSError *error);
|
||||
|
||||
@interface GiGaNetManager : NSObject
|
||||
|
||||
+ (void)requestMethod:(RequestMethod)requestMethod Url:(NSString *)url params:(NSDictionary *)params responseBlock:(responseBlock)block;
|
||||
|
||||
+(void)request:(NSString *)url params:(NSDictionary *)param
|
||||
success:(void (^)(id response))success
|
||||
failure:(void (^)(NSError *err))failure;
|
||||
+(void)userLoginrequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error))completionHandler;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,54 +9,58 @@
|
||||
#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];
|
||||
+ (void)requestMethod:(RequestMethod)requestMethod Url:(NSString *)url params:(NSDictionary *)params responseBlock:(responseBlock)block{
|
||||
|
||||
// NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
// NSURL *baseUrl = [NSURL URLWithString:[GiGaServerConfig getMainUrl]];
|
||||
// AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:configuration];
|
||||
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] init];
|
||||
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||||
switch (api.requestType) {
|
||||
case kRequestTypeGet:
|
||||
|
||||
switch (requestMethod) {
|
||||
case RequestGetMethod:
|
||||
|
||||
{
|
||||
[manager GET:api.fullUrl parameters:api.params progress:^(NSProgress * _Nonnull downloadProgress) {
|
||||
[manager GET:url parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
|
||||
|
||||
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
NSDictionary *outDic = (NSDictionary *)responseObject;
|
||||
[api callBackFinishedWithDictionary:outDic];
|
||||
|
||||
NSLog(@"%@", responseObject);
|
||||
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
|
||||
NSDictionary *headerFields = [(NSHTTPURLResponse *)task.response allHeaderFields];
|
||||
block(dict, headerFields, nil);
|
||||
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[api callBackFailed:error];
|
||||
NSDictionary *headerFields = [(NSHTTPURLResponse *)task.response allHeaderFields];
|
||||
block(nil, headerFields, error);
|
||||
}];
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case kRequestTypePost:
|
||||
case RequestPostMethod:
|
||||
{
|
||||
[manager POST:api.fullUrl parameters:api.params progress:^(NSProgress * _Nonnull uploadProgress) {
|
||||
|
||||
[manager POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
|
||||
|
||||
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
NSDictionary *outDic = (NSDictionary *)responseObject;
|
||||
[api callBackFinishedWithDictionary:outDic];
|
||||
|
||||
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
|
||||
NSLog(@"%@", dict);
|
||||
NSDictionary *headerFields = [(NSHTTPURLResponse *)task.response allHeaderFields];
|
||||
block(dict, headerFields, nil);
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[api callBackFailed:error];
|
||||
NSDictionary *headerFields = [(NSHTTPURLResponse *)task.response allHeaderFields];
|
||||
block(nil, headerFields, error);
|
||||
}];
|
||||
}
|
||||
break;
|
||||
@@ -67,6 +71,58 @@
|
||||
}
|
||||
}
|
||||
|
||||
+(void)request:(NSString *)url params:(NSDictionary *)param
|
||||
success:(void (^)(id response))success
|
||||
failure:(void (^)(NSError *err))failure
|
||||
{
|
||||
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] init];
|
||||
|
||||
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||||
|
||||
[manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
|
||||
|
||||
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
|
||||
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
|
||||
NSLog(@"%@", dict);
|
||||
if (success) {
|
||||
success(responseObject);
|
||||
}
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
NSLog(@"%@",error);
|
||||
if (failure) {
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
//登录body传参数
|
||||
+(void)userLoginrequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response,NSDictionary *resDic, NSError * _Nullable error))completionHandler
|
||||
{
|
||||
|
||||
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
NSURL *baseUrl = [NSURL URLWithString:[GiGaServerConfig getMainUrl]];
|
||||
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:configuration];
|
||||
NSMutableURLRequest *requst = [[AFJSONRequestSerializer serializer]
|
||||
requestWithMethod:@"POST" URLString:url parameters:param error:nil];
|
||||
requst.timeoutInterval = 10.f;
|
||||
[requst setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
[requst setValue:@"application/json" forHTTPHeaderField:@"Accept"];
|
||||
NSURLSessionDataTask *task = [manager dataTaskWithRequest:requst uploadProgress:^(NSProgress * _Nonnull uploadProgress) {
|
||||
|
||||
} downloadProgress:^(NSProgress * _Nonnull downloadProgress) {
|
||||
|
||||
} completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
|
||||
|
||||
if (completionHandler) {
|
||||
completionHandler(response,responseObject,error);
|
||||
}
|
||||
|
||||
}];
|
||||
|
||||
[task resume];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
|
||||
|
||||
@interface GiGaUserDefault : NSObject
|
||||
|
||||
//
|
||||
+(void)saveUserId:(NSString *)userId;
|
||||
+(void)saveToken:(NSString *)token;
|
||||
+(NSString *)getCurentToken;
|
||||
+(NSString *)getCurentUserId;
|
||||
+(void)removeUserId;//退出登录
|
||||
+(BOOL)isUserLogin;
|
||||
@@ -48,4 +50,5 @@
|
||||
+(NSDictionary *)getWeiXinAccessToenDic;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,13 +13,12 @@ NSString *const GIGADEFAULTKEY_USERID = @"GiGaUserId";
|
||||
NSString *const kShowUserGuard = @"ShowUserGuard";
|
||||
NSString *const kShowAppGuard = @"ShowAppGuard";
|
||||
NSString *const kWeiXinSaveToken = @"WeiXinSaveToken";
|
||||
NSString *const kGiGaToken = @"GiGatoken";
|
||||
|
||||
@implementation GiGaUserDefault
|
||||
|
||||
+(void)saveUserId:(NSString *)userId{
|
||||
|
||||
UD_SET_KEY_VALUE(GIGADEFAULTKEY_USERID, userId);
|
||||
|
||||
}
|
||||
|
||||
+(NSString*)getCurentUserId{
|
||||
@@ -28,12 +27,24 @@ NSString *const kWeiXinSaveToken = @"WeiXinSaveToken";
|
||||
return userid;
|
||||
}
|
||||
|
||||
+(void)saveToken:(NSString *)token{
|
||||
[UD_STADARDUD setObject:token forKey: kGiGaToken];
|
||||
[UD_STADARDUD synchronize];
|
||||
}
|
||||
|
||||
+(void)removeUserId{
|
||||
|
||||
UD_REMOVE_KEY(GIGADEFAULTKEY_USERID);
|
||||
|
||||
}
|
||||
|
||||
+(NSString *)getCurentToken{
|
||||
|
||||
NSString *token = [UD_STADARDUD objectForKey:kGiGaToken];
|
||||
[UD_STADARDUD synchronize];
|
||||
return token;
|
||||
}
|
||||
|
||||
+(BOOL)isUserLogin{
|
||||
|
||||
NSString *uid = UD_GET_VALUE(GIGADEFAULTKEY_USERID);
|
||||
|
||||
Reference in New Issue
Block a user