Latest 0.0.3
Homepage https://github.com/DaoPinWong/DPNetworking
License MIT
Platforms ios 8.0
Dependencies AFNetworking
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

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

pod "DPNetworking"

Usage

Quick to use

#import "DPNetworking.h"

  // 单例  只需要配置一次
    /************** 以下只是举例,请根据自身需要配置 **************/
    // 通用网络请求设置
    DPNetConfig *config = [DPNetConfig sharedManager];

    // 设置baseRUL
    config.baseURL = @"http://api.xxxx.com/app/";

    // 设置通用的头部信息
    config.HTTPHeaderDic = @{@"token" : @"xxxxxxxx", @"versions" : @"1.0.0"};

    // 设置返回格式
    config.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"application/json", @"text/jaon" ,@"text/javascript",@"text/html", nil];

    // 设置通用的请求失败处理
    config.failureBlock = ^BOOL(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSError *e = (NSError*)error;
        NSData *errorData = e.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
        if (errorData) {
            NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
            // 如判断token是否失效
            if ([serializedData[@"code"] integerValue] == 1010) {
                NSLog(@"token 失效");
                return NO;
            }
            NSLog(@"n error:%@ n ******************** n URL:%@",serializedData, error.userInfo[@"NSErrorFailingURLKey"]);
        }
        return YES;
    };

    /******************************************************/

    [DPNetworking get:@"xxxx"
               handle:^(DPNetworking * _Nonnull handle) {
                   // 如果对本次请求需要什么特殊设置,可以在此处设置
                   handle.requestSerializer.timeoutInterval = 15.f;
                   [handle.requestSerializer setValue:@"1" forHTTPHeaderField:@"status"];
               }
           parameters:@{@"key" : @"value"}
              success:^(id responseObject) {

              }
              failure:^(id error) {

              }];

Author

dpwong, [email protected]

License

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

Latest podspec

{
    "name": "DPNetworking",
    "version": "0.0.3",
    "summary": "u5bf9AFNetworkingu505au7684u4e8cu6b21u5c01u88c5uff0cu4e00u53e5u4ee3u7801u53d1u8d77u7f51u7edcu8bf7u6c42u3002",
    "description": "u5bf9AFNetworkingu505au7684u4e8cu6b21u5c01u88c5uff0cu4e00u53e5u4ee3u7801u53d1u8d77u7f51u7edcu8bf7u6c42u3002",
    "homepage": "https://github.com/DaoPinWong/DPNetworking",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "dpwong": "[email protected]"
    },
    "source": {
        "git": "https://github.com/DaoPinWong/DPNetworking.git",
        "tag": "0.0.3"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "DPNetworking/Classes/*.{h,m}",
    "dependencies": {
        "AFNetworking": []
    }
}

Pin It on Pinterest

Share This