LOG
接手一个新项目的时候,打印数据和控制器跳转等都不是很清楚,又不想动代码
#if DEBUG
#import "XAspect.h"
省去部分项目类
#define AspectLog(format, ...) printf("\n[%s]【Aspect--->】%s\n", __TIME__, [[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]);
#define AtAspect Log
#pragma mark - 控制器打印部分
#define AtAspectOfClass UIViewController
@classPatchField(UIViewController) //视图出现和dealloc
@synthesizeNucleusPatch(Default, -, void, viewDidAppear
: (BOOL)animated);
@synthesizeNucleusPatch(Default, -, void, dealloc);
AspectPatch(-, void, viewDidAppear
: (BOOL)animated) {
AspectLog(@"%@'s view did appear.", NSStringFromClass([self class]));
return XAMessageForward(viewDidAppear
: (BOOL)animated);
}
AspectPatch(-, void, dealloc) {
// if([self isKindOfClass:[UIViewController class]]){
AspectLog(@"%@ dealloc", NSStringFromClass([self class]));
// }
XAMessageForwardDirectly(dealloc);
}
@end
#undef AtAspectOfClass
#pragma mark - 网络请求打印部分
#define AtAspectOfClass XXXBaseRequestService
@classPatchField(XXXBaseRequestService) //网络请求参数
@synthesizeNucleusPatch(Default, -, void, postRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack);
@synthesizeNucleusPatch(Default, -, void, getRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack);
AspectPatch(-, void, postRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack) {
RequestBack bb = ^(BOOL requestSuccess, id response) {
BaseResultModel *model = [BaseResultModel modelWithJSON:response];
AspectLog(@"api:%@\n参数:%@\n返回:%@", url, [params yy_modelToJSONString], [model dicWithModel]);
requestBack(requestSuccess, response);
};
return XAMessageForward(postRequestWithUrl
: url Params
: params needHandle
: needHandle requestBack
: bb);
}
AspectPatch(-, void, getRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack) {
RequestBack bb = ^(BOOL requestSuccess, id response) {
BaseResultModel *model = [BaseResultModel modelWithJSON:response];
AspectLog(@"api:%@\n参数:%@\n返回:%@", url, [params yy_modelToJSONString], [model dicWithModel]);
requestBack(requestSuccess, response);
};
return XAMessageForward(getRequestWithUrl
: url Params
: params needHandle
: needHandle requestBack
: bb);
}
@end
#undef AtAspectOfClass
#pragma mark - XXXAppDelegate
#define AtAspectOfClass XXXAppDelegate
@classPatchField(XXXAppDelegate) //debug版本调试软件集成 闪退的时候记录下。无缘无故闪退不熟
@synthesizeNucleusPatch(Default, -, BOOL, application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions);
//@synthesizeNucleusPatch(Default, -, void, application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions);
AspectPatch(-, BOOL, application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions) {
[[JxbDebugTool shareInstance] setMainColor:[UIColor orangeColor]]; //设置主色调
[[JxbDebugTool shareInstance] enableDebugMode];//启用debug工具
return XAMessageForward(application:application didFinishLaunchingWithOptions:launchOptions);
}
@end
#undef AtAspectOfClass
#undef AtAspect
#endif
NETWORK
接手一个新项目的时候,Python脚本代码格式化影响较大,暂时不测试了。网络请求嵌了三层,忍无可忍,稍微优化一下。当然还是以前是自动更新Token的方案比较好,暂时这也是没有办法的办法了。
/**
优化网络请求前需要的二个block。注意需要过滤一个接口请求,不然是一个死循环。
*/
#define seoNetwork 1 //是否应用
#if DEBUG
#define AspectLog(format, ...) printf("\n[%s]【Aspect--->】%s\n", __TIME__, [[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]);
#define seoNetwork 1 //测试版应该
#else
#define AspectLog(format, ...)
#define seoNetwork 0 //发布版暂时不应用
#endif
#if seoNetwork
#import "XAspect.h"
#define AtAspect NetWork
#pragma mark - 网络请求打印部分
#define AtAspectOfClass XXXBaseRequestService
@classPatchField(XXXBaseRequestService) //网络请求参数
@synthesizeNucleusPatch(Default, -, void, postRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack);
@synthesizeNucleusPatch(Default, -, void, getRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack);
void checkXXXAAvailableWithCallback(TokenAccessCallback accessCallback) {
//逻辑。有个是网络请求再回调
}
void checkXXXBAvailableWithCallback(TokenAccessCallback accessCallback) {
//逻辑。退出
}
AspectPatch(-, void, postRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack) {
if ([url containsString:@"某个api"]) {
return XAMessageForward(postRequestWithUrl
: url Params
: params needHandle
: needHandle requestBack
: requestBack);
}
checkXXXAAvailableWithCallback(^{
checkXXXBAvailableWithCallback(^{
return XAMessageForward(postRequestWithUrl
: url Params
: params needHandle
: needHandle requestBack
: requestBack);
});
});
}
AspectPatch(-, void, getRequestWithUrl
: (NSString *)url Params
: (NSDictionary *)params needHandle
: (BOOL)needHandle requestBack
: (RequestBack)requestBack) {
if ([url containsString:@"某个api"]) {
return XAMessageForward(getRequestWithUrl
: url Params
: params needHandle
: needHandle requestBack
: requestBack);
}
checkXXXAAvailableWithCallback(^{
checkXXXBAvailableWithCallback(^{
return XAMessageForward(getRequestWithUrl
: url Params
: params needHandle
: needHandle requestBack
: requestBack);
});
});
}
@end
#undef AtAspectOfClass
#undef AtAspect
#endif