Skip to content

Commit

Permalink
ADD: allowsCellularAccess property
Browse files Browse the repository at this point in the history
Change-Id: Ief2f0a07f9bfed96d2bb063fb6b2bbf623890a9b
  • Loading branch information
liujl committed Aug 22, 2016
1 parent 9436033 commit aa89c02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion YTKNetwork/YTKBaseRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,15 @@ typedef void(^YTKRequestCompletionBlock)(__kindof YTKBaseRequest *request);
- (nullable NSDictionary<NSString *, NSString *> *)requestHeaderFieldValueDictionary;

/// Use this to build custom request. If this method return non-nil value, `requestUrl`, `requestTimeoutInterval`,
/// `requestArgument`, `requestMethod` and `requestSerializerType` will all be ignored.
/// `requestArgument`, `allowsCellularAccess`, `requestMethod` and `requestSerializerType` will all be ignored.
- (nullable NSURLRequest *)buildCustomUrlRequest;

/// Should use CDN when sending request.
- (BOOL)useCDN;

/// Whether the request is allowed to use the cellular radio (if present). Default is YES.
- (BOOL)allowsCellularAccess;

/// The validator will be used to test if `responseJSONObject` is correctly formed.
- (nullable id)jsonValidator;

Expand Down
4 changes: 4 additions & 0 deletions YTKNetwork/YTKBaseRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ - (BOOL)useCDN {
return NO;
}

- (BOOL)allowsCellularAccess {
return YES;
}

- (id)jsonValidator {
return nil;
}
Expand Down
3 changes: 3 additions & 0 deletions YTKNetwork/YTKNetworkAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ - (void)addRequest:(YTKBaseRequest *)request {
}

requestSerializer.timeoutInterval = [request requestTimeoutInterval];
requestSerializer.allowsCellularAccess = [request allowsCellularAccess];

// If api needs server username and password
NSArray<NSString *> *authorizationHeaderFieldArray = [request requestAuthorizationHeaderFieldArray];
Expand Down Expand Up @@ -182,6 +183,7 @@ - (void)addRequest:(YTKBaseRequest *)request {
NSString *filteredUrl = [YTKNetworkPrivate urlStringWithOriginUrlString:url appendParameters:param];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:filteredUrl]];
urlRequest.timeoutInterval = [request requestTimeoutInterval];
urlRequest.allowsCellularAccess = [request allowsCellularAccess];

NSString *downloadTargetPath;
BOOL isDirectory;
Expand Down Expand Up @@ -237,6 +239,7 @@ - (void)addRequest:(YTKBaseRequest *)request {
NSError *serializationError = nil;
NSMutableURLRequest *urlRequest = [requestSerializer multipartFormRequestWithMethod:@"POST" URLString:url parameters:param constructingBodyWithBlock:constructingBlock error:&serializationError];
urlRequest.timeoutInterval = [request requestTimeoutInterval];
urlRequest.allowsCellularAccess = [request allowsCellularAccess];

if (serializationError) {
dispatch_async(_manager.completionQueue ?: dispatch_get_main_queue(), ^{
Expand Down

3 comments on commit aa89c02

@sensencoder
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等待新的Demo,谢谢,,impatient

@skyline75489
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请在 Demo 文件夹下运行 pod install 然后打开 xcworkspace

@sensencoder
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢

Please sign in to comment.