CTNetworking is an iOS discrete HTTP API calling framework based on AFNetworking.Click for more detail(in Chinese)
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.
Just download or clone the whole project and DO NOT FORGET $ pod update --verbose
CTNetworking API URL is constituted by 4 part:
CTService+CTService Version+API method Name+API Parameters
Inherit CTService and follow CTServiceProtocal
@interface GDMapService : CTService <CTServiceProtocal>Implement all methods of CTServiceProtocal
...
- (NSString *)onlineApiBaseUrl
{
return @"http://restapi.amap.com";
}
- (NSString *)onlineApiVersion
{
return @"v3";
}
...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;
}
...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];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.
This code is distributed under the terms and conditions of the MIT license.