当我们写一个项目的时候,通常需要先写一个api,以便于调用,在此写一个具体代码实现,代码如下:
首先在.h中
#import
@interface SharkApi : YTKRequest
- (instancetype) initWithImageCount:(NSString *)imageCount istest:(NSString *)istest;
@end
其次在.m中
#import "SharkApi.h"
#import "NSString+Tools.h"
@interface SharkApi()
@property (nonatomic,copy) NSString *imageCount;
@property (nonatomic,copy) NSString *istest;
@end
@implementation SharkApi
- (instancetype)initWithImageCount:(NSString *)imageCount istest:(NSString *)istest{
if (self = [super init]) {
_imageCount = imageCount;
_istest = istest;
}
return self;
}
/**
设置请求接口
*/
- (NSString *)requestUrl{
return @"daydayself";
}
/**
设置请求超时时间
*/
- (NSTimeInterval)requestTimeoutInterval {
return 5;
}
/**
设置请求形式
*/
- (YTKRequestMethod)requestMethod {
return YTKRequestMethodPOST;
}
/**
设置请求参数
*/
- (id)requestArgument{
NSDictionary *parameter = @{
@"imageCount":_imageCount,
@"istest":_istest
};
return parameter;
}
/**
设置请求头
*/
- (NSDictionary *)requestHeaderFieldValueDictionary{
NSDictionary *hearderField = @{
@"Signature":@"80f4vspw",
@"Appid":@"ios",
@"X-System":@"iOS",
@"X-Device":@"iPhone6+",
@"Dpi": @"1080*1920",
@"X-Udid":[NSString deviceUUID]
};
return hearderField;
}
- (YTKResponseSerializerType)responseSerializerType{
return YTKResponseSerializerTypeHTTP;
}
@end