Latest 1.0.3
Homepage https://github.com/full-of-fire/YJNetworking
License MIT
Platforms ios 8.0
Dependencies AFNetworking, MJExtension
Authors

YJNetworking

CI Status
Version
License
Platform

Example

1、首先继承YJBaseApi,遵守YJBaseApiDelegate

@interface YJSendSmsApi : YJBaseApi<YJBaseApiDelegate>
@property (strong,nonatomic) NSString *phone;
@property (strong,nonatomic) NSString *type;

2、实现YJBaseApiDelegate协议

- (NSString*)path{
    return @"http://www.maijiaxiu365.com/buyershow-api/api/businessUser/send/sms";
}
- (NSString*)method{
    return kApiMethodPostForm;
}

mehod方法的可选值有GET,POST,’FileUpload’,’POSTForm’
path 方法返回的是请求的路径
3、配置网络请求的全局处理方式

    [YJApiProxy shareInstance].delegate = self;
    [YJApiProxy shareInstance].dataSource = self;
    @interface YJViewController ()<YJApiProxyDelegate,YJApiProxyDataSource>

    /**
 无网络处理

 @param apiProxy 网络请求单例
 */
- (void)hanlderNoNetwork:(YJApiProxy*)apiProxy {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前无网络连接" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil];
    [alertView show];
}

/**
 全局网络请求错误的处理

 @param error 错误
 @param errorMsg 常见的错误中文 如400,401,403,500等
 @param errorCode 错误码
 @param apiProxy 网络请求单例
 */
- (void)hanlderError:(NSError*)error errorMsg:(NSString*)errorMsg errorCode:(NSUInteger)errorCode apiPxoxy:(YJApiProxy*)apiProxy {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:errorMsg delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil];
    [alertView show];
}

// 全局处理
- (void)hanlderResponse:(id)response apiPxoxy:(YJApiProxy *)apiProxy{

    if ([response[@"code"] intValue] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"发送成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil];
        [alertView show];
    }else{
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:response[@"msg"] delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil];
        [alertView show];
    }
}

/**
 配置通用参数,比如登录后需要配置统一的token参数

 @param apiProxy 网络请求单例
 @return 通用参数
 */
- (NSDictionary*)globalParamsForApiProxy:(YJApiProxy*)apiProxy {

    return nil;
}

4、调用

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    _smsApi = [[YJSendSmsApi alloc] init];
    _smsApi.phone = @"17773903585";
    _smsApi.type = @"1";
    [_smsApi loadDataSuccess:^(id result) {

    } fail:^(NSError *error) {

    }];
}

Requirements

Installation

YJNetworking is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'YJNetwork'

Author

full-of-fire, [email protected]

License

YJNetworking is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "YJNetwork",
    "version": "1.0.3",
    "summary": "u79bbu6563u578bu7f51u7edcu8bf7u6c42",
    "description": "u79bbu6563u578bu7f51u7edcu8bf7u6c42,u51cfu5c11u7f51u7edcu8bf7u6c42crash",
    "homepage": "https://github.com/full-of-fire/YJNetworking",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "full-of-fire": "[email protected]"
    },
    "source": {
        "git": "https://github.com/full-of-fire/YJNetworking.git",
        "tag": "1.0.3"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "YJNetwork/Classes/**/*",
    "dependencies": {
        "AFNetworking": [],
        "MJExtension": []
    }
}

Pin It on Pinterest

Share This