-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,122 @@ | ||
# JCNetworking | ||
A useful iOS networking framework based on AFNetworking and JSONModel. | ||
A useful iOS networking framework based on [AFNetworking](https://github.com/AFNetworking/AFNetworking) and [JSONModel](https://github.com/icanzilb/JSONModel). | ||
|
||
## Features | ||
This framework supports the development of iOS 7.0+ in ARC. | ||
|
||
* Common request for GET/POST. | ||
* File or data upload. | ||
* File download (breakpoint downloading supported). | ||
|
||
### Common Request | ||
|
||
```objective-c | ||
//JCAccessTokenRequest.h | ||
@interface JCAccessTokenRequest : JCBaseRequest | ||
|
||
@property (nonatomic, strong) NSString *appid; | ||
@property (nonatomic, strong) NSString *secret; | ||
@property (nonatomic, strong) NSString *code; | ||
|
||
@end | ||
|
||
//JCAccessTokenRequest.m | ||
@implementation JCAccessTokenRequest | ||
|
||
- (NSString *)baseUrl | ||
{ | ||
return @"base url"; | ||
} | ||
|
||
- (NSString *)requestUrl | ||
{ | ||
return @"request url"; | ||
} | ||
|
||
@end | ||
``` | ||
```objective-c | ||
- (void)startGetRequest | ||
{ | ||
self.accessTokenRequest = [[JCAccessTokenRequest alloc] init]; | ||
self.accessTokenRequest.appid = @"your appid"; | ||
self.accessTokenRequest.secret = @"your secret"; | ||
self.accessTokenRequest.code = code; | ||
[self.accessTokenRequest startRequestWithDecodeClass:[JCAccessTokenResp class] completion:^(id responseObject, NSError *error) { | ||
//do something | ||
}]; | ||
} | ||
``` | ||
|
||
### Upload | ||
|
||
```objective-c | ||
//JCUploadTestRequest.h | ||
@interface JCUploadTestRequest : JCBaseRequest | ||
|
||
@end | ||
|
||
//JCUploadTestRequest.m | ||
@implementation JCUploadTestRequest | ||
|
||
- (JCRequestMethod)requestMethod | ||
{ | ||
return JCRequestMethodPOST; | ||
} | ||
|
||
- (NSString *)baseUrl | ||
{ | ||
return @"base url"; | ||
} | ||
|
||
- (NSString *)requestUrl | ||
{ | ||
return @"request url"; | ||
} | ||
|
||
@end | ||
``` | ||
```objective-c | ||
- (void)startUploadRequest | ||
{ | ||
self.uploadRequest = [[JCUploadTestRequest alloc] init]; | ||
[self.uploadRequest setUploadFilePath:@"file path" | ||
uploadName:@"file"]; | ||
[self.uploadRequest startRequestWithDecodeClass:[JCBaseResp class] completion:^(id responseObject, NSError *error) { | ||
//do something | ||
}]; | ||
} | ||
``` | ||
|
||
### Download | ||
|
||
```objective-c | ||
- (void)startDownloadOperation | ||
{ | ||
JCDownloadItem *downloadItem = [[JCDownloadItem alloc] init]; | ||
downloadItem.downloadUrl = @"download url"; | ||
downloadItem.downloadFilePath = @"download file path"; | ||
JCDownloadOperation *operation = [[JCDownloadQueue sharedQueue] downloadOperation:downloadItem.downloadId | ||
groupId:downloadItem.groupId]; | ||
if (!operation) { | ||
operation = [[JCDownloadOperation alloc] init]; | ||
operation.item = downloadItem; | ||
} | ||
[operation startWithProgressBlock:^(NSProgress *progress) { | ||
//update progress | ||
} completionBlock:^(NSURL *filePath, NSError *error) { | ||
//download operation completion, do something | ||
}]; | ||
} | ||
``` | ||
|
||
## CocoaPods | ||
To integrate JCNetworking into your iOS project, specify it in your Podfile: | ||
|
||
pod 'JCNetworking' | ||
|
||
|
||
## License | ||
JCNetworking is released under the [MIT License](https://github.com/Boych/JCNetworking/blob/master/LICENSE). |