Latest 1.3.2
Homepage https://github.com/Hyosung/ACSNetworking
License MIT
Platforms ios 7.0, osx 10.9, requires ARC
Authors

ACSNetworking是一个依赖于AFNetworking的网络请求的库,其主要目的是为了使用更便捷,更高效。初次写库,如有什么写的不对或是不好的地方还请在Issues指出。

怎么导入项目中?

直接导入

下载 ACSNetworking 然后导入到你的iOS或者OSX项目中,注意你还得下载 AFNetworking

使用CocoaPods

Podfile

platform :ios, '7.0'
pod "ACSNetworking", "~> 1.3"

Requester

  • ACSURLHTTPRequester
  • ACSFileDownloader
  • ACSFileUploader

Cache

  • ACSCache

Configuration

  • ACSNetworkConfiguration

Reachability

  • ACSNetworkReachabilityManager

RequestManager

  • ACSRequestManager

用法

Configuration

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [ACSNetworkConfiguration defaultConfiguration].baseURL = [NSURL URLWithString:@"http://example.com"];
    [ACSNetworkConfiguration defaultConfiguration].cacheExpirationTimeInterval = 180.0;
    [ACSNetworkConfiguration defaultConfiguration].downloadExpirationTimeInterval = 60.0 * 60.0 * 24.0 * 7;

    [ACSNetworkConfiguration defaultConfiguration].securityPolicy = [AFSecurityPolicy defaultPolicy];

    return YES;
}

GET Request

// Block
ACSRequestManager *manager = [ACSRequestManager manager];
ACSURLHTTPRequester *requester = ACSCreateGETRequester([NSURL URLWithString:@"http://example.com/resources.json"], nil, ^(id result, NSError *error) {
        if (result) {
            NSLog(@"responseObject %@", result);
        }
        else {
            NSLog(@"Error %@", error);
        }
    });
[manager fetchDataFromRequester:requester];
// Delegate
ACSRequestManager *manager = [ACSRequestManager manager];
ACSURLHTTPRequester *requester = ACSCreateGETRequester([NSURL URLWithString:@"http://example.com/resources.json"], nil, self);
[manager fetchDataFromRequester:requester];

- (void)request:(ACSHTTPRequest *)requester didFailToRequestForDataWithError:(NSError *)error {
    NSLog(@"Error %@", error);
}

- (void)request:(ACSHTTPRequest *)requester didFailToProcessForDataWithError:(NSError *)error {
    NSLog(@"Process Error %@", error);
}

- (void)request:(ACSHTTPRequest *)requester didReceiveData:(id)data {
    NSLog(@"responseObject %@", data);
}

GET Download Request

// Block
ACSRequestManager *manager = [ACSRequestManager manager];
ACSFileDownloader *requester = ACSCreateDownloader([NSURL URLWithString:@"http://example.com/resources.json"],
                                                   ^(ACSRequestProgress progress, NSString *filePath, NSError *error) {
                                                       if (error) {
                                                           NSLog(@"Error %@", error);
                                                       }
                                                       else {
                                                           if (!filePath) {
                                                               NSLog(@"responseObject %@", filePath);
                                                           }
                                                           else {
                                                               NSLog(@"Progress %f", progress.progressValue);
                                                           }
                                                       }
                                                   });
[manager fetchDataFromRequester:requester];
//Delegate
......

POST URL-Form-Encoded Request

// Block
ACSRequestManager *manager = [ACSRequestManager manager];
ACSURLHTTPRequester *requester = ACSCreatePOSTRequester([NSURL URLWithString:@"http://example.com/resources.json"], nil, ^(id result, NSError *error) {
        if (result) {
            NSLog(@"responseObject %@", result);
        }
        else {
            NSLog(@"Error %@", error);
        }
    });
[manager fetchDataFromRequester:requester];
// Delegate
ACSRequestManager *manager = [ACSRequestManager manager];
ACSURLHTTPRequester *requester = ACSCreatePOSTRequester([NSURL URLWithString:@"http://example.com/resources.json"], nil, self);
[manager fetchDataFromRequester:requester];

- (void)request:(ACSHTTPRequest *)requester didFailToRequestForDataWithError:(NSError *)error {
    NSLog(@"Error %@", error);
}

- (void)request:(ACSHTTPRequest *)requester didFailToProcessForDataWithError:(NSError *)error {
    NSLog(@"Process Error %@", error);
}

- (void)request:(ACSHTTPRequest *)requester didReceiveData:(id)data {
    NSLog(@"responseObject %@", data);
}

POST Multi-Part Request

// Block
ACSRequestManager *manager = [ACSRequestManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
UIImage *image = [UIImage imageNamed:@"imageName"];
NSDictionary *fileInfo = @{@"image": image};
//fileInfo = @{@"image": @"file://path/to/image.png"};
//fileInfo = @{@"image": [NSURL URLWithString:@"file://path/to/image.png"]};
//fileInfo = @{@"image": [NSData dataWithContentsOfFile:@"file://path/to/image.png"]};
ACSFileUploader *requester = ACSCreateUploader([NSURL URLWithString:@"http://example.com/resources.json"],
                                                fileInfo,
                                                ^(ACSRequestProgress progress, id result, NSError *error) {
                                                    if (error) {
                                                       NSLog(@"Error %@", error);
                                                    }
                                                    else {
                                                        if (result) {
                                                            NSLog(@"responseObject %@", result);
                                                        }
                                                        else {
                                                            NSLog(@"Progress %f", progress.progressValue);
                                                        }
                                                    }
                                                });
requester.parameters = parameters;
[manager fetchDataFromRequester:requester];
// Delegate
ACSRequestManager *manager = [ACSRequestManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
UIImage *image = [UIImage imageNamed:@"imageName"];
NSDictionary *fileInfo = @{@"image": image};
ACSFileUploader *requester = ACSCreateUploader([NSURL URLWithString:@"http://example.com/resources.json"],
                                                fileInfo,
                                                self);
requester.parameters = parameters;
[manager fetchDataFromRequester:requester];
......
- (void)request:(ACSHTTPRequest *)requester didFileProgressing:(ACSRequestProgress)progress {
    NSLog(@"Progress %f", progress.progressValue);
}

License

ACSNetworking is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "ACSNetworking",
    "version": "1.3.2",
    "summary": "On the basis of AFNetworking encapsulation.",
    "description": "On the basis of AFNetworking encapsulation, more convenient, more concise.",
    "homepage": "https://github.com/Hyosung/ACSNetworking",
    "license": "MIT",
    "authors": {
        "Stoney": "[email protected]"
    },
    "social_media_url": "http://weibo.com/sy4312xx",
    "platforms": {
        "ios": "7.0",
        "osx": "10.9"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/Hyosung/ACSNetworking.git",
        "tag": "1.3.2"
    },
    "public_header_files": "ACSNetworking/ACSNetworking.h",
    "source_files": "ACSNetworking/ACSNetworking.h",
    "default_subspecs": "Requester",
    "subspecs": [
        {
            "name": "General",
            "dependencies": {
                "AFNetworking": [
                    "~> 2.6.0"
                ]
            },
            "source_files": "ACSNetworking/ACSNetworkGeneral.h"
        },
        {
            "name": "Reachability",
            "source_files": "ACSNetworking/ACSReachability.{h,m}",
            "public_header_files": "ACSNetworking/ACSReachability.h",
            "frameworks": "SystemConfiguration",
            "ios": {
                "frameworks": [
                    "CoreTelephony",
                    "UIKit"
                ]
            }
        },
        {
            "name": "BaseRequester",
            "dependencies": {
                "ACSNetworking/General": []
            },
            "source_files": "ACSNetworking/ACS*Request.{h,m}",
            "public_header_files": "ACSNetworking/ACS*Request.h"
        },
        {
            "name": "Foundation",
            "source_files": "ACSNetworking/NSData+ACSMimeType.*",
            "public_header_files": "ACSNetworking/NSData+ACSMimeType.h",
            "ios": {
                "frameworks": "MobileCoreServices"
            },
            "osx": {
                "frameworks": "CoreServices"
            }
        },
        {
            "name": "Cache",
            "dependencies": {
                "ACSNetworking/General": []
            },
            "source_files": "ACSNetworking/ACSCache.{h,m}",
            "public_header_files": "ACSNetworking/ACSCache.h",
            "ios": {
                "frameworks": "UIKit"
            }
        },
        {
            "name": "Configuration",
            "dependencies": {
                "ACSNetworking/General": [],
                "ACSNetworking/Cache": []
            },
            "source_files": "ACSNetworking/ACSNetworkConfiguration.*",
            "public_header_files": "ACSNetworking/ACSNetworkConfiguration.h",
            "ios": {
                "frameworks": "UIKit"
            }
        },
        {
            "name": "Requester",
            "dependencies": {
                "ACSNetworking/General": [],
                "ACSNetworking/Reachability": [],
                "ACSNetworking/Cache": [],
                "ACSNetworking/Configuration": [],
                "ACSNetworking/Foundation": [],
                "ACSNetworking/BaseRequester": []
            },
            "source_files": "ACSNetworking/ACS*er.{h,m}",
            "public_header_files": "ACSNetworking/ACS*er.h",
            "ios": {
                "frameworks": [
                    "UIKit",
                    "MobileCoreServices"
                ]
            },
            "osx": {
                "frameworks": [
                    "AppKit",
                    "CoreServices"
                ]
            }
        }
    ]
}

Pin It on Pinterest

Share This