TimCore分为core核心库和TimJpush、TimShare、TimBaseViewModel、TimAFAppConnectClient几个子模块,子模块都可以独立使用,互不影响,
//定义
@interface TimCoreAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
+(TimCoreAppDelegate*)shareInstance;
@end
///继承使用--推送部分
@interface TimCoreAppDelegate (myJpush)
///code
@end
+(void)load
{
[super load];
///设置极光的 push 方案
[TimJpushConfigManager sharedInstance].enableJpush = YES;
[TimJpushConfigManager sharedInstance].pushAppKey = @"XXXX";
[TimJpushConfigManager sharedInstance].apsForProduction = YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
///不能忘记
[super application:application didFinishLaunchingWithOptions:launchOptions];
__weak AppDelegate *weak_self =self;
self.pushBlock = ^(NSDictionary *userInfo, UIApplicationState state){
///do it by yourself
//STRONG_SELF
};
return YES;
}
typedef void(^ShareResult)(BOOL sucess,NSString *msg);
@interface AppDelegate(share)
-(void)initSharedSDK;
-(void)shareInfo:(NSString *)title content:(NSString *)content image:(id)image url:(NSString *)url actionSheet:(UIView *)actionSheet onShareStateChanged:(ShareResult)shareStateChangedHandler;
@end
-(void)initialize {
[super initialize];
///设置请求地址 self.path = @"show-img/view"; @weakify(self) ///处理上传数据 self.inputBlock = ^(NSMutableDictionary *para ) {
@strongify(self) if (para && self. id ) { [para setObject:self.id forKey:@"id"]; } return para; }; ///处理图片上传数据, 基于AF self.formDataInputBlock = ^(id _Nullable formData) { @strongify(self)
if (self.object.img) { NSInteger I =0 ; for (UIImage *image in @[self.object.img] ) { NSData *data = UIImagePNGRepresentation(image); if(data == nil){ data = UIImageJPEGRepresentation(image,1); } if(data){ [formData appendPartWithFileData:data name:[NSString stringWithFormat:@"pic[%ld]",I++] fileName:@"pic.png"mimeType:@"image/png" ]; } } };
///非列表数据输出
self.outputBlock = ^(NSDictionary *para ) { @strongify(self) self.obj = [[XXXDetailObject alloc] mj_setKeyValues:para]; return self.obj ; };
///列表数据输出
self.block = ^NSArray *(NSDictionary *dict){ return [xxxxObject mj_objectArrayWithKeyValuesArray: dict ]; };
}
<h1>TimAFAppConnectClient</h1>
<ul>
<li>TimAFAppConnectClient 基于 AF 3.0 做的一个简化网络请求的设置模块,支持 设置 基本的数据来过滤 非正常状态码的数据,简化大量网络请求的代码</li>
````objectivec
///设置状态码等基本数据
-(void)setSucessCode:(NSInteger)sucessCode statusCodeKey:(NSString *_Nonnull)statusCodeKey msgKey:(NSString *_Nonnull)msgKey responseDataKey:(NSString * _Nonnull)responseDataKey;
///常见 post 请求
/**
* POST请求
*
* @param methodName 方法名
* @param param 参数
* @param checkNullData 检查data是否为空
* @param successBlock 成功回调
* @param failedBlock 失败回调
*/
- (void)skPostWithMethodName:(NSString *_Nonnull)methodName
param:(NSDictionary * _Nullable )param
checkNullData:(BOOL)checkNullData
successBlock:(void(^_Nullable)(NSURLSessionDataTask * _Nonnull task, id _Nullable json))successBlock
failedBlock:(void(^_Nullable)(NSURLSessionDataTask * _Nonnull task, id _Nullable json, SKErrorMsgType errorType, NSError *_Nullable error))failedBlock;