Skip to content

Instantly share code, notes, and snippets.

@maojj
Created May 15, 2015 16:11
Show Gist options
  • Save maojj/4a5bf51fd0597f253e05 to your computer and use it in GitHub Desktop.
Save maojj/4a5bf51fd0597f253e05 to your computer and use it in GitHub Desktop.
// 使用方法
YTKNetworkConfig *config = [YTKNetworkConfig sharedInstance];
UIDevice *device = [UIDevice currentDevice];
NSString *platFormString = [device platformAndOSVersion];
[config addUrlFilter:[YTKUrlArgumentsFilter filterWithArguments:@{ @"version": APP_VERSION,
@"UDID": [device uniqueGlobalDeviceIdentifier],
@"platform" : platFormString}]];
//
// 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
//
// 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