To run the example project, clone the repo, and run pod install
from the Example directory first.
Minimum iOS Target:iOS 11.0
RCSceneNetworkKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RCSceneNetworkKit'
通过添加 RCSNetworkConfig
分类配置请求信息,和添加 RCSNetworkDataHandler
分类发起请求
/// 可添加全局网络配置
[RCSNetworkConfig configWithBaseUrl:@"" bussinessToken:@""];
/// 通过 RCSNetworkDataHandler 实例对象发起请求
[[RCSNetworkDataHandler new] sendCodeWithParams:@{} completionBlock:^(RCSResponseModel * _Nonnull model) {
NSLog(@"%@", model.description);
}];
// RCSNetworkConfig+Login.h
@interface RCSNetworkConfig (Login)
/// 获取登录验证码
+ (RCSNetworkConfig *)sendCodeUrlConfigWith:(NSDictionary *)params;
@end
// RCSNetworkConfig+Login.m
@implementation RCSNetworkConfig (Login)
/// 获取登录验证码
+ (RCSNetworkConfig *)sendCodeUrlConfigWith:(NSDictionary *)params {
return [self configWithUrl:[[RCSLoginConfig baseUrl] stringByAppendingPathComponent:@"user/sendCode"]
rspClassName:nil
method:RCSHTTPRequestMethodPOST
params:params
headers:[self login_commonHeaders]];
}
+ (NSDictionary *)login_commonHeaders{
NSMutableDictionary *header = @{@"Content-Type":@"application/json"}.mutableCopy;
if ([RCSLoginConfig bussinessToken].length != 0) {
[header addEntriesFromDictionary:@{@"BusinessToken":[RCSLoginConfig bussinessToken]}];
}
return header.copy;
}
@end
// RCSNetworkDataHandler+Login.h
@interface RCSNetworkDataHandler (Login)
/// 登录验证码
- (void)sendCodeWithParams:(NSDictionary * _Nullable)params
completionBlock:(RCSNetworkCompletion _Nullable)completionBlock;
@end
// RCSNetworkDataHandler+Login.m
@implementation RCSNetworkDataHandler (Login)
/// 登录验证码
- (void)sendCodeWithParams:(NSDictionary * _Nullable)params
completionBlock:(RCSNetworkCompletion _Nullable)completionBlock {
RCSNetworkConfig *config = [RCSNetworkConfig sendCodeUrlConfigWith:params];
[self requestWithUrlConfig:config completion:completionBlock];
}
@end
RCSceneNetworkKit is available under the MIT license. See the LICENSE file for more info.