Created
May 15, 2015 16:11
-
-
Save maojj/4a5bf51fd0597f253e05 to your computer and use it in GitHub Desktop.
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
// 使用方法 | |
YTKNetworkConfig *config = [YTKNetworkConfig sharedInstance]; | |
UIDevice *device = [UIDevice currentDevice]; | |
NSString *platFormString = [device platformAndOSVersion]; | |
[config addUrlFilter:[YTKUrlArgumentsFilter filterWithArguments:@{ @"version": APP_VERSION, | |
@"UDID": [device uniqueGlobalDeviceIdentifier], | |
@"platform" : platFormString}]]; |
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
// | |
// Created by Chenyu Lan on 8/27/14. | |
// Copyright (c) 2014 Fenbi. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "YTKNetworkConfig.h" | |
#import "YTKBaseRequest.h" | |
// 给url追加arguments,用于全局参数,比如AppVersion, ApiVersion等 | |
@interface YTKUrlArgumentsFilter : NSObject <YTKUrlFilterProtocol> | |
+ (YTKUrlArgumentsFilter *)filterWithArguments:(NSDictionary *)arguments; | |
- (NSString *)filterUrl:(NSString *)originUrl withRequest:(YTKBaseRequest *)request; | |
@end |
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
// | |
// Created by Chenyu Lan on 8/27/14. | |
// Copyright (c) 2014 Fenbi. All rights reserved. | |
// | |
#import "YTKUrlArgumentsFilter.h" | |
#import "YTKNetworkPrivate.h" | |
@implementation YTKUrlArgumentsFilter { | |
NSDictionary *_arguments; | |
} | |
+ (YTKUrlArgumentsFilter *)filterWithArguments:(NSDictionary *)arguments { | |
return [[self alloc] initWithArguments:arguments]; | |
} | |
- (id)initWithArguments:(NSDictionary *)arguments { | |
self = [super init]; | |
if (self) { | |
_arguments = arguments; | |
} | |
return self; | |
} | |
- (NSString *)filterUrl:(NSString *)originUrl withRequest:(YTKBaseRequest *)request { | |
if (request.useCDN) { | |
return originUrl; | |
} else { | |
return [YTKNetworkPrivate urlStringWithOriginUrlString:originUrl appendParameters:_arguments]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment