The networking layer for iOS App.
Objective-C Ruby
Latest commit 453e5a1 Oct 21, 2016 @casatwy fixed a bug
Permalink
Failed to load latest commit information.
AIFNetworking.key more details in readme May 27, 2016
CTNetworking.xcodeproj modification Oct 21, 2016
CTNetworking fixed a bug Oct 21, 2016
.gitignore ctnetworking 1.0.0 May 27, 2016
LICENSE init May 26, 2016
Podfile old May 27, 2016
readme.md Fixed a typo in readme. Sep 19, 2016

readme.md

CTNetworking

Join the chat at https://gitter.im/casatwy/RTNetworking

CTNetworking is an iOS discrete HTTP API calling framework based on AFNetworking.Click for more detail(in Chinese)

Requirements

CTNetworking works on iOS 8.0+ and requires ARC to build. It depends on the following Apple frameworks, which should already be included with most Xcode templates:

  • Foundation.framework
  • UIKit.framework
  • CoreGraphics.framework
  • QuartzCore.framework
  • AFNetworking

You will need the latest developer tools in order to build CTNetworking. Old Xcode versions might work, but compatibility will not be explicitly maintained.

Adding CTNetworking to your project

Demo

Just download or clone the whole project and DO NOT FORGET $ pod update --verbose

Usage

Call API

CTNetworking API URL is constituted by 4 part:

CTService+CTService Version+API method Name+API Parameters

Custom a CTService

Inherit CTService and follow CTServiceProtocol

@interface GDMapService : CTService <CTServiceProtocol>

Implement all methods of CTServiceProtocol

...
- (NSString *)onlineApiBaseUrl
{
    return @"http://restapi.amap.com";
}
- (NSString *)onlineApiVersion
{
    return @"v3";
}
...

Custom an APIManager

Inherit CTAPIBaseManager and follow CTAPIManager Protocal

@interface TestAPIManager : CTAPIBaseManager <CTAPIManager>

Implement all methods of CTAPIManager

...
- (NSString *)methodName
{
    return @"geocode/regeo";
}

- (NSString *)serviceType
{
    return kCTServiceGDMapV3;
}

- (CTAPIManagerRequestType)requestType
{
    return CTAPIManagerRequestTypeGet;
}
...

Call API

Instantiation of API Manager in class

@property (nonatomic, strong) TestAPIManager *testAPIManager;

- (TestAPIManager *)testAPIManager
{
    if (_testAPIManager == nil) {
        _testAPIManager = [[TestAPIManager alloc] init];
        _testAPIManager.delegate = self;
        _testAPIManager.paramSource = self;
    }
    return _testAPIManager;
}

Implement methods of CTAPIManagerParamSource and CTAPIManagerCallBackDelegate

#pragma mark - CTAPIManagerParamSource
- (NSDictionary *)paramsForApi:(CTAPIBaseManager *)manager
{
    return parmas;
}

#pragma mark - CTAPIManagerCallBackDelegate
- (void)managerCallAPIDidSuccess:(CTAPIBaseManager *)manager
{
    //do something
}
- (void)managerCallAPIDidFailed:(CTAPIBaseManager *)manager
{
    //do something
}

And easy to use

[self.testAPIManager loadData];

AppContext settings

You SHOULD custom CTAppContext to set App networking layer settings. Also, you can add more settings to use.

See more in demo and Click for more detail(in Chinese)

Enjoy.

License

This code is distributed under the terms and conditions of the MIT license.