Commit 1ab32e11 by houweibin

1,API缓存 (品牌商品列表页面,分类页面,首页,博客列表,所有品牌)

2,Moncler商品详情显示 contact us 按钮
3,去掉商品详情页面图片的自动滚动
4,其他
parent 2e8141bf
...@@ -242,6 +242,8 @@ ...@@ -242,6 +242,8 @@
C066650C1D75A2E500F02EF4 /* Mine.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C06665081D75A2E500F02EF4 /* Mine.storyboard */; }; C066650C1D75A2E500F02EF4 /* Mine.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C06665081D75A2E500F02EF4 /* Mine.storyboard */; };
C066650F1D7675FC00F02EF4 /* KWMAboutUsVC.m in Sources */ = {isa = PBXBuildFile; fileRef = C066650E1D7675FC00F02EF4 /* KWMAboutUsVC.m */; }; C066650F1D7675FC00F02EF4 /* KWMAboutUsVC.m in Sources */ = {isa = PBXBuildFile; fileRef = C066650E1D7675FC00F02EF4 /* KWMAboutUsVC.m */; };
C06665121D767A0A00F02EF4 /* KWMContactUsVC.m in Sources */ = {isa = PBXBuildFile; fileRef = C06665111D767A0A00F02EF4 /* KWMContactUsVC.m */; }; C06665121D767A0A00F02EF4 /* KWMContactUsVC.m in Sources */ = {isa = PBXBuildFile; fileRef = C06665111D767A0A00F02EF4 /* KWMContactUsVC.m */; };
C06F5D811FBA9381005BC5AF /* CacheKeyConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = C06F5D801FBA9381005BC5AF /* CacheKeyConstants.m */; };
C06F5D841FBAA5D0005BC5AF /* KWMPPCacheUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = C06F5D831FBAA5D0005BC5AF /* KWMPPCacheUtil.m */; };
C07267821F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m in Sources */ = {isa = PBXBuildFile; fileRef = C07267811F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m */; }; C07267821F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m in Sources */ = {isa = PBXBuildFile; fileRef = C07267811F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m */; };
C07267851F1616E500C5A869 /* KWMColor.m in Sources */ = {isa = PBXBuildFile; fileRef = C07267841F1616E500C5A869 /* KWMColor.m */; }; C07267851F1616E500C5A869 /* KWMColor.m in Sources */ = {isa = PBXBuildFile; fileRef = C07267841F1616E500C5A869 /* KWMColor.m */; };
C077966F1EEAA2BE00CD6859 /* KWMFilterUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = C077966E1EEAA2BE00CD6859 /* KWMFilterUtil.m */; }; C077966F1EEAA2BE00CD6859 /* KWMFilterUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = C077966E1EEAA2BE00CD6859 /* KWMFilterUtil.m */; };
...@@ -797,6 +799,10 @@ ...@@ -797,6 +799,10 @@
C066650E1D7675FC00F02EF4 /* KWMAboutUsVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMAboutUsVC.m; sourceTree = "<group>"; }; C066650E1D7675FC00F02EF4 /* KWMAboutUsVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMAboutUsVC.m; sourceTree = "<group>"; };
C06665101D767A0A00F02EF4 /* KWMContactUsVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMContactUsVC.h; sourceTree = "<group>"; }; C06665101D767A0A00F02EF4 /* KWMContactUsVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMContactUsVC.h; sourceTree = "<group>"; };
C06665111D767A0A00F02EF4 /* KWMContactUsVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMContactUsVC.m; sourceTree = "<group>"; }; C06665111D767A0A00F02EF4 /* KWMContactUsVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMContactUsVC.m; sourceTree = "<group>"; };
C06F5D7F1FBA9381005BC5AF /* CacheKeyConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CacheKeyConstants.h; sourceTree = "<group>"; };
C06F5D801FBA9381005BC5AF /* CacheKeyConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CacheKeyConstants.m; sourceTree = "<group>"; };
C06F5D821FBAA5D0005BC5AF /* KWMPPCacheUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KWMPPCacheUtil.h; sourceTree = "<group>"; };
C06F5D831FBAA5D0005BC5AF /* KWMPPCacheUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KWMPPCacheUtil.m; sourceTree = "<group>"; };
C07267801F15D62400C5A869 /* NSLayoutConstraint+Multiplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+Multiplier.h"; sourceTree = "<group>"; }; C07267801F15D62400C5A869 /* NSLayoutConstraint+Multiplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+Multiplier.h"; sourceTree = "<group>"; };
C07267811F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+Multiplier.m"; sourceTree = "<group>"; }; C07267811F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+Multiplier.m"; sourceTree = "<group>"; };
C07267831F1616E500C5A869 /* KWMColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMColor.h; sourceTree = "<group>"; }; C07267831F1616E500C5A869 /* KWMColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMColor.h; sourceTree = "<group>"; };
...@@ -1295,6 +1301,8 @@ ...@@ -1295,6 +1301,8 @@
C034E68E1D6AEB12006EE129 /* main.m */, C034E68E1D6AEB12006EE129 /* main.m */,
C034E6E91D6AF0A0006EE129 /* Header-Prefix.h */, C034E6E91D6AF0A0006EE129 /* Header-Prefix.h */,
C034E6EA1D6AF0A0006EE129 /* Localizable.strings */, C034E6EA1D6AF0A0006EE129 /* Localizable.strings */,
C06F5D7F1FBA9381005BC5AF /* CacheKeyConstants.h */,
C06F5D801FBA9381005BC5AF /* CacheKeyConstants.m */,
); );
name = "Supporting Files"; name = "Supporting Files";
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1489,6 +1497,8 @@ ...@@ -1489,6 +1497,8 @@
9B8298E21EF22BE200743438 /* KWMCurrencyUtil.m */, 9B8298E21EF22BE200743438 /* KWMCurrencyUtil.m */,
C03120AE1EF2B26B00E49EFA /* KWMPayUtil.h */, C03120AE1EF2B26B00E49EFA /* KWMPayUtil.h */,
C03120AF1EF2B26B00E49EFA /* KWMPayUtil.m */, C03120AF1EF2B26B00E49EFA /* KWMPayUtil.m */,
C06F5D821FBAA5D0005BC5AF /* KWMPPCacheUtil.h */,
C06F5D831FBAA5D0005BC5AF /* KWMPPCacheUtil.m */,
); );
path = Util; path = Util;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -2516,7 +2526,7 @@ ...@@ -2516,7 +2526,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
F84386F9A53E1205C21D5570 /* [CP] Copy Pods Resources */ = { F84386F9A53E1205C21D5570 /* [CP] Copy Pods Resources */ = {
...@@ -2585,6 +2595,7 @@ ...@@ -2585,6 +2595,7 @@
C0028EC51F0DD19C00744C14 /* KWMAdditionalResult.m in Sources */, C0028EC51F0DD19C00744C14 /* KWMAdditionalResult.m in Sources */,
C03943C01DD1FCE900141475 /* KWMProductType.m in Sources */, C03943C01DD1FCE900141475 /* KWMProductType.m in Sources */,
C0CC140C1D7829FC007B5986 /* KWMSelectSizeVC.m in Sources */, C0CC140C1D7829FC007B5986 /* KWMSelectSizeVC.m in Sources */,
C06F5D841FBAA5D0005BC5AF /* KWMPPCacheUtil.m in Sources */,
C00D40971F187CAB00DEA685 /* KWMCategoryTitleView.m in Sources */, C00D40971F187CAB00DEA685 /* KWMCategoryTitleView.m in Sources */,
C034E7B31D6AFC3B006EE129 /* KWMMainVC.m in Sources */, C034E7B31D6AFC3B006EE129 /* KWMMainVC.m in Sources */,
C08FDA2A1D9B583400EBDB0D /* KWMGiftCardVC.m in Sources */, C08FDA2A1D9B583400EBDB0D /* KWMGiftCardVC.m in Sources */,
...@@ -2776,6 +2787,7 @@ ...@@ -2776,6 +2787,7 @@
C034E7C21D6B0B62006EE129 /* KWMMineVC.m in Sources */, C034E7C21D6B0B62006EE129 /* KWMMineVC.m in Sources */,
DA8D64121F31C67F00B8F4A6 /* DeepLinkURLProtocol.m in Sources */, DA8D64121F31C67F00B8F4A6 /* DeepLinkURLProtocol.m in Sources */,
C08FDA271D9A5F3400EBDB0D /* KWMAddGiftCardVC.m in Sources */, C08FDA271D9A5F3400EBDB0D /* KWMAddGiftCardVC.m in Sources */,
C06F5D811FBA9381005BC5AF /* CacheKeyConstants.m in Sources */,
C07267821F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m in Sources */, C07267821F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m in Sources */,
C02C7D9E1E643323008DC29C /* KWMShareVC.m in Sources */, C02C7D9E1E643323008DC29C /* KWMShareVC.m in Sources */,
C034E68F1D6AEB12006EE129 /* main.m in Sources */, C034E68F1D6AEB12006EE129 /* main.m in Sources */,
......
//
// CacheKeyConstants.h
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
/** 此文件存放缓存时用到的key **/
extern NSString *const CACHE_KEY_FAIL_HINT;
extern NSString *const CACHE_KEY_SDK_getProductsPage;
extern NSString *const CACHE_KEY_getHomeDataWithSuccess;
extern NSString *const CACHE_KEY_SDK_getCollectionByHandle;
extern NSString *const CACHE_KEY_SDK_getCollectionByHandle_getProductsPage;
//
// CacheKeyConstants.m
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
NSString *const CACHE_KEY_FAIL_HINT = @"网络已断开,请重新连接";
NSString *const CACHE_KEY_SDK_getCollectionByHandle = @"MobileSDK-getCollectionByHandle";
NSString *const CACHE_KEY_SDK_getCollectionByHandle_getProductsPage = @"MobileSDK-getCollectionByHandle_getProductsPage";
NSString *const CACHE_KEY_SDK_getProductsPage = @"MobileSDK-getProductsPage";
NSString *const CACHE_KEY_getHomeDataWithSuccess = @"getHomeDataWithSuccess";
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "AFNetworking.h" #import "AFNetworking.h"
#import <PPNetworkHelper/PPNetworkHelper.h>
#import "KWMRequestListResult.h" #import "KWMRequestListResult.h"
#import "KWMRequestResult.h" #import "KWMRequestResult.h"
#import "KWMCemaroseResult.h" #import "KWMCemaroseResult.h"
...@@ -145,6 +146,7 @@ ...@@ -145,6 +146,7 @@
* @return NSURLSessionDataTask * @return NSURLSessionDataTask
*/ */
- (NSURLSessionDataTask *) getAllBrand:(NSDictionary *)parameters - (NSURLSessionDataTask *) getAllBrand:(NSDictionary *)parameters
cacheCallback:(void(^)(KWMBrandsResult *result))cacheCallback
success:(void(^)(NSURLSessionDataTask *task,KWMBrandsResult *result))success success:(void(^)(NSURLSessionDataTask *task,KWMBrandsResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure; failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
...@@ -162,6 +164,7 @@ ...@@ -162,6 +164,7 @@
* @return NSURLSessionDataTask * @return NSURLSessionDataTask
*/ */
- (NSURLSessionDataTask *) getAllBlog:(NSDictionary *)parameters - (NSURLSessionDataTask *) getAllBlog:(NSDictionary *)parameters
cacheCallback:(void(^)(KWMBlogResult *result))cacheCallback
success:(void(^)(NSURLSessionDataTask *task,KWMBlogResult *result))success success:(void(^)(NSURLSessionDataTask *task,KWMBlogResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure; failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
- (NSURLSessionDataTask *) getAllPage:(NSDictionary *)parameters - (NSURLSessionDataTask *) getAllPage:(NSDictionary *)parameters
......
...@@ -25,9 +25,8 @@ ...@@ -25,9 +25,8 @@
#import "KWMUserModel.h" #import "KWMUserModel.h"
#import "KWMHttpUtil.h" #import "KWMHttpUtil.h"
#import "KWMHomeDataResult.h" #import "KWMHomeDataResult.h"
#import <PPNetworkHelper/PPNetworkHelper.h>
/** 使用API缓存(isNeedCache为True)的请求的链接必须是完整的,因为PPNetworkHelper里的Sessionmanage是一开始就初始化了, BaseUrl无法设置 **/
typedef NS_ENUM(NSInteger, KWMHTTPMethod) { typedef NS_ENUM(NSInteger, KWMHTTPMethod) {
KWMHTTPMethodGET = 0, KWMHTTPMethodGET = 0,
...@@ -36,6 +35,8 @@ typedef NS_ENUM(NSInteger, KWMHTTPMethod) { ...@@ -36,6 +35,8 @@ typedef NS_ENUM(NSInteger, KWMHTTPMethod) {
KWMHTTPMethodDELETE KWMHTTPMethodDELETE
}; };
@implementation KWMAPIManager @implementation KWMAPIManager
+ (KWMAPIManager *)sharedManager { + (KWMAPIManager *)sharedManager {
...@@ -68,6 +69,79 @@ typedef NS_ENUM(NSInteger, KWMHTTPMethod) { ...@@ -68,6 +69,79 @@ typedef NS_ENUM(NSInteger, KWMHTTPMethod) {
return _baseUrl; return _baseUrl;
} }
-(void(^)(NSError *error))buildNewFaliedCallback:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
void(^failedCallback)(NSError *error) =
^(NSError *error){
failure(nil, error);
};
return failedCallback;
}
- (void(^)(id responseObject))buildNewCacheCallbackWithResultCalss:
(Class)requestResultClass
modelClass:(Class)modelClass
callback:(void (^)(id responseObject))callback
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
if(!callback){
return nil;
}
void(^cacheCallback)(id responseObject) =
^(id responseObject){
NSError *error;
if(!responseObject){
callback(nil);
}else{
id result = nil;
@try {
result = [[requestResultClass alloc] initWithDictionary:responseObject modelClass:modelClass error:&error];
}
@catch (NSException *e){
NSLog(@"%@", [e description]);
}
@finally{
[self checkRequestResult:result];
if(error){
failure(nil, error);
}else{
callback(result);
}
}
}
};
return cacheCallback;
}
- (void(^)(id responseObject))buildNewSuccessCallbackWithResultCalss:
(Class)requestResultClass
modelClass:(Class)modelClass
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
void(^successCallback)(id responseObject) =
^(id responseObject){
NSError *error;
if(!responseObject){
success(nil, nil);
}else{
id result = nil;
@try {
result = [[requestResultClass alloc] initWithDictionary:responseObject modelClass:modelClass error:&error];
}
@catch (NSException *e){
NSLog(@"%@", [e description]);
}
@finally{
[self checkRequestResult:result];
if(error){
failure(nil, error);
}else{
success(nil, result);
}
}
}
};
return successCallback;
}
/** /**
* 根据API返回类型,模型类型创建成功callback * 根据API返回类型,模型类型创建成功callback
*/ */
...@@ -159,13 +233,18 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -159,13 +233,18 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
- (AFHTTPSessionManager *)buildSessionManager{ - (AFHTTPSessionManager *)buildSessionManager{
return [self buildSessionManager:NO]; return [self buildSessionManager:NO afSessionManage:nil];
} }
- (AFHTTPSessionManager *)buildSessionManager:(BOOL)isJsonParameter{ - (AFHTTPSessionManager *)buildSessionManager:(BOOL)isJsonParameter afSessionManage:(AFHTTPSessionManager *)afSessionManage{
NSURL *url = [NSURL URLWithString:self.baseUrl]; NSURL *url = [NSURL URLWithString:self.baseUrl];
AFHTTPSessionManager *sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:url]; AFHTTPSessionManager *sessionManager;
if(afSessionManage){
sessionManager = afSessionManage;
}else{
sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
}
//设置超时时间为10秒 //设置超时时间为10秒
// [sessionManager.requestSerializer willChangeValueForKey:@"timeoutInterval"]; // [sessionManager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
sessionManager.requestSerializer.timeoutInterval = 10.f; sessionManager.requestSerializer.timeoutInterval = 10.f;
...@@ -203,7 +282,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -203,7 +282,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
result:(Class)result result:(Class)result
model:(Class)model model:(Class)model
success:(void (^)(NSURLSessionDataTask *task, id result))success success:(void (^)(NSURLSessionDataTask *task, id result))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{ failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
cacheCallback:(void (^)( id result))cacheCallback
isNeedCache:(Boolean)isNeedCache{
NSAssert((result == [KWMRequestResult class] || result == [KWMRequestListResult class] NSAssert((result == [KWMRequestResult class] || result == [KWMRequestListResult class]
...@@ -212,12 +293,26 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -212,12 +293,26 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
@"result class must either be KWMRequestResult or KWMRequestListResult!"); @"result class must either be KWMRequestResult or KWMRequestListResult!");
NSAssert((!model || (model && [model isSubclassOfClass:[JSONModel class]])), NSAssert((!model || (model && [model isSubclassOfClass:[JSONModel class]])),
@"model class must be sub class of JSONModel"); @"model class must be sub class of JSONModel");
//使用sessionManager请求时用到的callback
void(^successCallback)(NSURLSessionDataTask *, id ) = [self buildSuccessCallbackWithResultClass:result void(^successCallback)(NSURLSessionDataTask *, id ) = [self buildSuccessCallbackWithResultClass:result
modelClass:model modelClass:model
success:success success:success
failure:failure]; failure:failure];
AFHTTPSessionManager *sessionManager = [self buildSessionManager:isJsonParameter];
//使用PPNetworkHelper请求时用到的callback
void(^newSuccessCallback)(id responseObject) = [self buildNewSuccessCallbackWithResultCalss:result
modelClass:model
success:success
failure:failure];
//使用PPNetworkHelper请求时用到的缓存callback
void(^newCacheCallback)(id responseObject) = [self buildNewCacheCallbackWithResultCalss:result
modelClass:model
callback:cacheCallback
failure:failure];
//使用PPNetworkHelper请求失败时用到的callback
void(^newFailedCallback)(NSError *error) = [self buildNewFaliedCallback:failure];
AFHTTPSessionManager *sessionManager = [self buildSessionManager:isJsonParameter afSessionManage:nil];
if (timeout) { if (timeout) {
[sessionManager.requestSerializer setTimeoutInterval:timeout]; [sessionManager.requestSerializer setTimeoutInterval:timeout];
} }
...@@ -232,6 +327,13 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -232,6 +327,13 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
// mutableParameters[KEY_OS_VERSION] = [NSString stringWithFormat:@"ios%@", [UIDevice currentDevice].systemVersion]; // mutableParameters[KEY_OS_VERSION] = [NSString stringWithFormat:@"ios%@", [UIDevice currentDevice].systemVersion];
// NSLog(@"os_version:%@=====", mutableParameters[KEY_OS_VERSION]); // NSLog(@"os_version:%@=====", mutableParameters[KEY_OS_VERSION]);
//初始化PPNetworkHelper里的sessionManager
[PPNetworkHelper setAFHTTPSessionManagerProperty:^(AFHTTPSessionManager *sessionManager) {
if (timeout) {
[sessionManager.requestSerializer setTimeoutInterval:timeout];
}
[self buildSessionManager:isJsonParameter afSessionManage:sessionManager];
}];
if (filePaths != nil && filePaths.count > 0) { if (filePaths != nil && filePaths.count > 0) {
return [sessionManager POST:apiPath parameters:mutableParameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { return [sessionManager POST:apiPath parameters:mutableParameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
...@@ -285,14 +387,23 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -285,14 +387,23 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
if(parameters.allKeys==nil || parameters.allKeys.count==0){ if(parameters.allKeys==nil || parameters.allKeys.count==0){
parameters = nil; parameters = nil;
} }
switch (httpMethod) { switch (httpMethod) {
case KWMHTTPMethodGET:{ case KWMHTTPMethodGET:{
if(isNeedCache && newCacheCallback){
id task = [PPNetworkHelper GET:apiPath parameters:parameters responseCache:newCacheCallback success:newSuccessCallback failure:newFailedCallback];
return [task isKindOfClass:[NSURLSessionDataTask class]] ? task : nil;
}else{
return [sessionManager GET:apiPath parameters:parameters success:successCallback failure:failure]; return [sessionManager GET:apiPath parameters:parameters success:successCallback failure:failure];
} }
}
case KWMHTTPMethodPOST:{ case KWMHTTPMethodPOST:{
if(isNeedCache && newCacheCallback){
id task = [PPNetworkHelper POST:apiPath parameters:parameters responseCache:newCacheCallback success:newSuccessCallback failure:newFailedCallback];
return [task isKindOfClass:[NSURLSessionDataTask class]] ? task : nil;
}else{
return [sessionManager POST:apiPath parameters:parameters success:successCallback failure:failure]; return [sessionManager POST:apiPath parameters:parameters success:successCallback failure:failure];
} }
}
case KWMHTTPMethodPUT:{ case KWMHTTPMethodPUT:{
return [sessionManager PUT:apiPath parameters:parameters success:successCallback failure:failure]; return [sessionManager PUT:apiPath parameters:parameters success:successCallback failure:failure];
} }
...@@ -319,7 +430,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -319,7 +430,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
result:(Class)result result:(Class)result
model:(Class)model model:(Class)model
success:(void (^)(NSURLSessionDataTask *task, id result))success success:(void (^)(NSURLSessionDataTask *task, id result))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
cacheCallback:(void (^)( id result))cacheCallback
isNeedCache:(Boolean)isNeedCache{
return [self startSessionTask:httpMethod return [self startSessionTask:httpMethod
apiPath:apiPath apiPath:apiPath
...@@ -331,7 +444,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -331,7 +444,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
result:result result:result
model:model model:model
success:success success:success
failure:failure]; failure:failure
cacheCallback:cacheCallback
isNeedCache:isNeedCache];
} }
- (NSURLSessionDataTask *)makeSessionTask:(KWMHTTPMethod)httpMethod - (NSURLSessionDataTask *)makeSessionTask:(KWMHTTPMethod)httpMethod
...@@ -346,7 +461,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -346,7 +461,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
modelClass:model modelClass:model
success:success success:success
failure:failure]; failure:failure];
AFHTTPSessionManager *sessionManager = [self buildSessionManager:NO]; AFHTTPSessionManager *sessionManager = [self buildSessionManager:NO afSessionManage:nil];
NSString *method = httpMethod == KWMHTTPMethodPOST ? @"POST" : @"GET"; NSString *method = httpMethod == KWMHTTPMethodPOST ? @"POST" : @"GET";
NSURLRequest *request = [sessionManager.requestSerializer requestWithMethod:method URLString:apiPath parameters:parameters error:nil]; NSURLRequest *request = [sessionManager.requestSerializer requestWithMethod:method URLString:apiPath parameters:parameters error:nil];
__block id task = [sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { __block id task = [sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
...@@ -366,7 +481,29 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -366,7 +481,29 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
result:(Class)result result:(Class)result
model:(Class)model model:(Class)model
success:(void (^)(NSURLSessionDataTask *task, id result))success success:(void (^)(NSURLSessionDataTask *task, id result))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
cacheCallback:(void (^)( id result))cacheCallback
isNeedCache:(Boolean)isNeedCache{
return [self startSessionTask:httpMethod
apiPath:apiPath
parameters:parameters
filePaths:nil
jsonParameter:NO
result:result
model:model
success:success failure:failure
cacheCallback:cacheCallback
isNeedCache:isNeedCache];
}
//比上面的方法少isNeedCache和cacheCallback
- (NSURLSessionDataTask *)startSessionTask:(KWMHTTPMethod)httpMethod
apiPath:(NSString *)apiPath
parameters:(NSDictionary *)parameters
result:(Class)result
model:(Class)model
success:(void (^)(NSURLSessionDataTask *task, id result))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
return [self startSessionTask:httpMethod return [self startSessionTask:httpMethod
apiPath:apiPath apiPath:apiPath
parameters:parameters parameters:parameters
...@@ -374,7 +511,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -374,7 +511,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
jsonParameter:NO jsonParameter:NO
result:result result:result
model:model model:model
success:success failure:failure]; success:success failure:failure cacheCallback:nil isNeedCache:NO];
} }
- (NSString *)toIds:(NSArray<__kindof NSString *> *)idsArray { - (NSString *)toIds:(NSArray<__kindof NSString *> *)idsArray {
...@@ -537,10 +674,11 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -537,10 +674,11 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
* 获取所有品牌 * 获取所有品牌
*/ */
- (NSURLSessionDataTask *) getAllBrand:(NSDictionary *)parameters - (NSURLSessionDataTask *) getAllBrand:(NSDictionary *)parameters
cacheCallback:(void(^)(KWMBrandsResult *result))cacheCallback
success:(void(^)(NSURLSessionDataTask *task,KWMBrandsResult *result))success success:(void(^)(NSURLSessionDataTask *task,KWMBrandsResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{ failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = @"shopifyapps/product_search/cemarose/brands"; NSString *apiPath = [NSString stringWithFormat:@"%@/shopifyapps/product_search/cemarose/brands",self.baseUrl];
return [self startSessionTask:KWMHTTPMethodGET return [self startSessionTask:KWMHTTPMethodGET
apiPath:apiPath apiPath:apiPath
...@@ -548,7 +686,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -548,7 +686,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
result:[KWMBrandsResult class] result:[KWMBrandsResult class]
model:nil model:nil
success:success success:success
failure:failure]; failure:failure
cacheCallback:cacheCallback
isNeedCache:YES];
} }
/** /**
...@@ -558,7 +698,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -558,7 +698,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
- (NSURLSessionDataTask *) searchProduct:(NSDictionary *)parameters - (NSURLSessionDataTask *) searchProduct:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMSearchResult *result))success success:(void(^)(NSURLSessionDataTask *task,KWMSearchResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{ failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = @"shopifyapps/product_search/cemarose/search"; NSString *apiPath = [NSString stringWithFormat:@"%@/shopifyapps/product_search/cemarose/search",self.baseUrl];
return [self startSessionTask:KWMHTTPMethodGET return [self startSessionTask:KWMHTTPMethodGET
apiPath:apiPath apiPath:apiPath
parameters:parameters parameters:parameters
...@@ -572,6 +712,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -572,6 +712,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
* 博客API * 博客API
*/ */
- (NSURLSessionDataTask *) getAllBlog:(NSDictionary *)parameters - (NSURLSessionDataTask *) getAllBlog:(NSDictionary *)parameters
cacheCallback:(void(^)(KWMBlogResult *result))cacheCallback
success:(void(^)(NSURLSessionDataTask *task,KWMBlogResult *result))success success:(void(^)(NSURLSessionDataTask *task,KWMBlogResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{ failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = [[NSString alloc] initWithFormat:@"https://%@/admin/articles.json",Shopify_SHOP_DOMAIN]; NSString *apiPath = [[NSString alloc] initWithFormat:@"https://%@/admin/articles.json",Shopify_SHOP_DOMAIN];
...@@ -581,7 +722,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -581,7 +722,9 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
result:[KWMBlogResult class] result:[KWMBlogResult class]
model:nil model:nil
success:success success:success
failure:failure]; failure:failure
cacheCallback:cacheCallback
isNeedCache:YES];
} }
- (NSURLSessionDataTask *) getAllPage:(NSDictionary *)parameters - (NSURLSessionDataTask *) getAllPage:(NSDictionary *)parameters
...@@ -826,7 +969,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -826,7 +969,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
// model:[KWMWechatPayData class] // model:[KWMWechatPayData class]
// success:success // success:success
// failure:failure]; // failure:failure];
return [self startSessionTask:KWMHTTPMethodPOST apiPath:apiPath parameters:parameters filePaths:nil timeout:30 images:nil jsonParameter:NO result:[KWMCheckoutPayResult class] model:[KWMWechatPayData class] success:success failure:failure]; return [self startSessionTask:KWMHTTPMethodPOST apiPath:apiPath parameters:parameters filePaths:nil timeout:30 images:nil jsonParameter:NO result:[KWMCheckoutPayResult class] model:[KWMWechatPayData class] success:success failure:failure cacheCallback:nil isNeedCache:NO];
} }
/** /**
...@@ -850,7 +993,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -850,7 +993,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
// model:nil // model:nil
// success:success // success:success
// failure:failure]; // failure:failure];
return [self startSessionTask:KWMHTTPMethodPOST apiPath:apiPath parameters:parameters filePaths:nil timeout:30 images:nil jsonParameter:NO result:[KWMCheckoutPayResult class] model:nil success:success failure:failure]; return [self startSessionTask:KWMHTTPMethodPOST apiPath:apiPath parameters:parameters filePaths:nil timeout:30 images:nil jsonParameter:NO result:[KWMCheckoutPayResult class] model:nil success:success failure:failure cacheCallback:nil isNeedCache:NO];
} }
- (NSURLSessionDataTask *) wechatPayOrderQuery:(NSDictionary *)parameters - (NSURLSessionDataTask *) wechatPayOrderQuery:(NSDictionary *)parameters
......
...@@ -128,17 +128,25 @@ ...@@ -128,17 +128,25 @@
<constraint firstAttribute="height" constant="30" id="HK4-OE-vEa"/> <constraint firstAttribute="height" constant="30" id="HK4-OE-vEa"/>
</constraints> </constraints>
</view> </view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kkz-NK-BGC">
<rect key="frame" x="0.0" y="0.0" width="375" height="64"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints> <constraints>
<constraint firstAttribute="bottom" secondItem="IcS-3H-XUB" secondAttribute="bottom" id="0j4-ln-dzu"/> <constraint firstAttribute="bottom" secondItem="IcS-3H-XUB" secondAttribute="bottom" id="0j4-ln-dzu"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="top" secondItem="zpX-41-Ngk" secondAttribute="top" constant="64" id="1ku-fw-1rl"/> <constraint firstItem="hDa-nl-Tlr" firstAttribute="top" secondItem="6iQ-dc-23W" secondAttribute="bottom" constant="44" id="5UQ-kj-JaO"/>
<constraint firstAttribute="trailing" secondItem="kkz-NK-BGC" secondAttribute="trailing" id="5Z1-ce-Sci"/>
<constraint firstAttribute="trailing" secondItem="evT-5t-rty" secondAttribute="trailing" id="67h-A6-5jJ"/> <constraint firstAttribute="trailing" secondItem="evT-5t-rty" secondAttribute="trailing" id="67h-A6-5jJ"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="top" secondItem="kkz-NK-BGC" secondAttribute="bottom" id="7mJ-4u-nZA"/>
<constraint firstItem="kkz-NK-BGC" firstAttribute="top" secondItem="zpX-41-Ngk" secondAttribute="top" id="9Hm-Pk-FQC"/>
<constraint firstItem="IcS-3H-XUB" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="CIl-uD-o0w"/> <constraint firstItem="IcS-3H-XUB" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="CIl-uD-o0w"/>
<constraint firstAttribute="trailing" secondItem="IcS-3H-XUB" secondAttribute="trailing" id="Cv2-YS-e4D"/> <constraint firstAttribute="trailing" secondItem="IcS-3H-XUB" secondAttribute="trailing" id="Cv2-YS-e4D"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="NhL-d5-aXA"/> <constraint firstItem="hDa-nl-Tlr" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="NhL-d5-aXA"/>
<constraint firstItem="kkz-NK-BGC" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="OXr-gn-pes"/>
<constraint firstItem="evT-5t-rty" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="Og9-68-h35"/> <constraint firstItem="evT-5t-rty" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="Og9-68-h35"/>
<constraint firstItem="HuL-FJ-3YQ" firstAttribute="top" secondItem="Cy8-TS-7aW" secondAttribute="bottom" id="PIf-9Z-uEf"/> <constraint firstAttribute="bottom" secondItem="Cy8-TS-7aW" secondAttribute="bottom" id="Svy-Uy-Rgg"/>
<constraint firstItem="IcS-3H-XUB" firstAttribute="top" secondItem="hDa-nl-Tlr" secondAttribute="bottom" id="VMa-R5-OFW"/> <constraint firstItem="IcS-3H-XUB" firstAttribute="top" secondItem="hDa-nl-Tlr" secondAttribute="bottom" id="VMa-R5-OFW"/>
<constraint firstAttribute="bottom" secondItem="evT-5t-rty" secondAttribute="bottom" id="XDr-SL-NMM"/> <constraint firstAttribute="bottom" secondItem="evT-5t-rty" secondAttribute="bottom" id="XDr-SL-NMM"/>
<constraint firstAttribute="trailing" secondItem="hDa-nl-Tlr" secondAttribute="trailing" id="a3q-U2-mJY"/> <constraint firstAttribute="trailing" secondItem="hDa-nl-Tlr" secondAttribute="trailing" id="a3q-U2-mJY"/>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#import "KWMFilterVC.h" #import "KWMFilterVC.h"
#import "KWMShoppingCart.h" #import "KWMShoppingCart.h"
#import "KWMSearchFeedbackVC.h" #import "KWMSearchFeedbackVC.h"
#import "KWMPPCacheUtil.h"
@interface KWMBrandCaramelVC ()<UITableViewDelegate,UITableViewDataSource,KWMBrandCaramelCellDelegate> @interface KWMBrandCaramelVC ()<UITableViewDelegate,UITableViewDataSource,KWMBrandCaramelCellDelegate>
@property (nonatomic) KWMBarandSelectView *barandSelectView; @property (nonatomic) KWMBarandSelectView *barandSelectView;
...@@ -65,29 +66,8 @@ ...@@ -65,29 +66,8 @@
[self initView]; [self initView];
[self getCollection:_handle]; [self getCollection:_handle];
if(self.goodModel){
[self initCacheData];
}
} }
-(void)initCacheData{
if(self.goodModel){
NSArray *products = [self.userDao getCollectionCache:self.goodModel.id tags:_isSale?[NSArray arrayWithObjects:@"sale", nil]:nil];
if(products && products.count>0){
[self appendDataList:products setPage:1];
self.currentPage = 0;
}
}else if(self.collection!=nil && self.collection.identifier!=nil){
NSArray *products = [self.userDao getCollectionCache:self.collection.identifier tags:_isSale?[NSArray arrayWithObjects:@"sale", nil]:nil];
if(products && products.count>0){
[self appendDataList:products setPage:1];
self.currentPage = 0;
}
}
}
- (void)setBackColor{ - (void)setBackColor{
colorArr = [NSArray arrayWithObjects:@"#D8A88D",@"#A4C8C6",@"#E6C995",@"#718473",@"#D7B48B", nil]; colorArr = [NSArray arrayWithObjects:@"#D8A88D",@"#A4C8C6",@"#E6C995",@"#718473",@"#D7B48B", nil];
int num = arc4random_uniform(10); int num = arc4random_uniform(10);
...@@ -303,7 +283,6 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -303,7 +283,6 @@ static NSString *idStr = @"KWMBrandCaramelCell";
} }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 244; return 244;
} }
...@@ -314,13 +293,18 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -314,13 +293,18 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}else if([KWMStringUtil isEmpty:collectionHandle]){ }else if([KWMStringUtil isEmpty:collectionHandle]){
return; return;
} }
NSDictionary *parameters = @{@"handle":handle};
BOOL canUseCacheCollection = [self canUseCacheCollection:parameters];
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) { [self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
if(!error){
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle collection:collection];
}
if(collection && !error){ if(collection && !error){
self.collection = collection; self.collection = collection;
[self setBrandData]; [self setBrandData];
//如果已经拿到缓存中collection,getProduct则已经调用过了。
if(!canUseCacheCollection){
[self getProcduct:collection.identifier]; [self getProcduct:collection.identifier];
if(!self.goodModel){
[self initCacheData];
} }
}else if(error != nil){ }else if(error != nil){
[self showError:error]; [self showError:error];
...@@ -362,7 +346,14 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -362,7 +346,14 @@ static NSString *idStr = @"KWMBrandCaramelCell";
[self.tbvBrandCaramel.mj_footer resetNoMoreData]; [self.tbvBrandCaramel.mj_footer resetNoMoreData];
} }
NSInteger tagetPage = self.currentPage.integerValue + 1; NSInteger tagetPage = self.currentPage.integerValue + 1;
NSDictionary *parameters = [KWMPPCacheUtil getProductPageCacheKey:tagetPage pageSize:self.client.pageSize sortOrder:collectionSort tags:tags inCollection:collectionId];
if([self isUseCacheProduct:parameters page:tagetPage]){
return;
};
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){ [self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
if (!error){
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
}
if (error) { if (error) {
[self showError:error]; [self showError:error];
NSLog(@"Error fetching products: %@", error); NSLog(@"Error fetching products: %@", error);
...@@ -371,17 +362,14 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -371,17 +362,14 @@ static NSString *idStr = @"KWMBrandCaramelCell";
[weakSelf.dataList removeAllObjects]; [weakSelf.dataList removeAllObjects];
[self.tbvBrandCaramel reloadData]; [self.tbvBrandCaramel reloadData];
}else if (error == nil && products) { }else if (error == nil && products) {
// if(tagetPage == 1){
if(tagetPage == 1 && (tags.count == 0 || (tags.count == 1 && weakSelf.isSale)) ){ [weakSelf.dataList removeAllObjects];
[weakSelf.userDao saveCollectionCache:products collectionId:collectionId tags:tags];
} }
//
weakSelf.hasNextPage = !reachedEnd; weakSelf.hasNextPage = !reachedEnd;
[weakSelf appendDataList:products setPage:page]; [weakSelf appendDataList:products setPage:page];
weakSelf.vNoneGoods.hidden = YES; weakSelf.vNoneGoods.hidden = YES;
[self.tbvBrandCaramel reloadData]; [self.tbvBrandCaramel reloadData];
// [weakSelf.dataList addObjectsFromArray:products]; // [weakSelf.dataList addObjectsFromArray:products];
// [weakSelf.tbvBrandCaramel.mj_header endRefreshing]; // [weakSelf.tbvBrandCaramel.mj_header endRefreshing];
// [weakSelf.tbvBrandCaramel.mj_footer endRefreshing]; // [weakSelf.tbvBrandCaramel.mj_footer endRefreshing];
...@@ -391,4 +379,40 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -391,4 +379,40 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}]; }];
} }
#pragma mark -cache
//缓存规则:第一页数据默认先从缓存拿,然后再更新,后面的根据网络判断从缓存拿数据还是从api拿数据
- (BOOL)isUseCacheProduct:(NSDictionary *)cacheKeyDictionary page:(NSUInteger)page{
if(!kIsNetwork || page==1){
NSArray *cacheProducts = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getProductsPage];
if(cacheProducts && cacheProducts.count > 0){
self.vNoneGoods.hidden = YES;
if(page == 1){
[self.dataList removeAllObjects];
}
self.hasNextPage = YES;
[self appendDataList:cacheProducts setPage:page];
[self.tbvBrandCaramel reloadData];
}else if(!kIsNetwork){
[self showToast:CACHE_KEY_FAIL_HINT];
}
}
return !kIsNetwork;
}
//缓存规则:默认拿缓存数据,api依旧照常执行,不过执行过的getProduct api不会重新执行
-(BOOL)canUseCacheCollection:(NSDictionary *)cacheKeyDictionary{
BUYCollection *collection = [KWMPPCacheUtil getCollectionByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle];
if(collection){
self.collection = collection;
[self setBrandData];
[self getProcduct:collection.identifier];
return true;
}else{
return false;
}
}
@end @end
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
@interface KWMSearchBrandVC ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,KWMSearchBrandViewDelegate> @interface KWMSearchBrandVC ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,KWMSearchBrandViewDelegate>
@property (nonatomic,strong) NSMutableArray *dataArray; @property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic)KWMSearchBrandView *searchBrandView; @property (nonatomic,weak)KWMSearchBrandView *searchBrandView;
@end @end
@implementation KWMSearchBrandVC { @implementation KWMSearchBrandVC {
...@@ -32,20 +32,16 @@ ...@@ -32,20 +32,16 @@
- (void)viewWillDisappear:(BOOL)animated{ - (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated]; [super viewWillDisappear:animated];
[_searchBrandView removeFromSuperview];
searchArr = nil;
searchTitle = nil;
} }
- (void)viewWillAppear:(BOOL)animated{ - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; [super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES]; [self.navigationController setNavigationBarHidden:YES];
[self initHeaderView];
} }
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self initHeaderView];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
self.automaticallyAdjustsScrollViewInsets = NO; self.automaticallyAdjustsScrollViewInsets = NO;
self.title = @"所有品牌"; self.title = @"所有品牌";
...@@ -67,8 +63,9 @@ ...@@ -67,8 +63,9 @@
} }
- (void)initHeaderView{ - (void)initHeaderView{
self.searchBrandView = [[KWMSearchBrandView alloc] init]; KWMSearchBrandView *searchBrandView = [[KWMSearchBrandView alloc] init];
[self.view addSubview:_searchBrandView]; [self.view addSubview:searchBrandView];
self.searchBrandView = searchBrandView;
self.searchBrandView.delegate = self; self.searchBrandView.delegate = self;
[self initCustomTitleBarConstarints:self.searchBrandView]; [self initCustomTitleBarConstarints:self.searchBrandView];
} }
...@@ -313,13 +310,26 @@ static NSString *identify = @"KWMSearchBrandsCell"; ...@@ -313,13 +310,26 @@ static NSString *identify = @"KWMSearchBrandsCell";
return ; return ;
} }
// NSArray *indexArray= [result.brands arrayWithPinYinFirstLetterFormat]; // NSArray *indexArray= [result.brands arrayWithPinYinFirstLetterFormat];
if(self.dataArray){ //如果已经从缓存拿到数据了。
return;
}
NSArray *indexArray= [[result.brands rx_filterWithBlock:^BOOL(id each) {
return each && each != [NSNull null];
}] arrayWithPinYinFirstLetterFormat];
_dataArray =[NSMutableArray arrayWithArray:indexArray];
[weakSelf.tbvSearchBrand reloadData];
};
void(^cacheCallback)(KWMBrandsResult *) = ^(KWMBrandsResult *result){
if([weakSelf hasCemaroseError:result]){
return ;
}
NSArray *indexArray= [[result.brands rx_filterWithBlock:^BOOL(id each) { NSArray *indexArray= [[result.brands rx_filterWithBlock:^BOOL(id each) {
return each && each != [NSNull null]; return each && each != [NSNull null];
}] arrayWithPinYinFirstLetterFormat]; }] arrayWithPinYinFirstLetterFormat];
_dataArray =[NSMutableArray arrayWithArray:indexArray]; _dataArray =[NSMutableArray arrayWithArray:indexArray];
[weakSelf.tbvSearchBrand reloadData]; [weakSelf.tbvSearchBrand reloadData];
}; };
[self.api getAllBrand:nil success:success failure:failure]; [self.api getAllBrand:nil cacheCallback:cacheCallback success:success failure:failure];
// [self showLoading]; // [self showLoading];
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#import "KWMFilterUtil.h" #import "KWMFilterUtil.h"
#import "MJRefresh.h" #import "MJRefresh.h"
#import "KWMShoppingCart.h" #import "KWMShoppingCart.h"
#import "CacheKeyConstants.h"
#import "KWMPPCacheUtil.h"
...@@ -284,15 +286,26 @@ ...@@ -284,15 +286,26 @@
-(void)requestAllBrandsApi{ -(void)requestAllBrandsApi{
__weak KWMCategoryVC *weakSelf = self; __weak KWMCategoryVC *weakSelf = self;
void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){ void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
//如果从缓存拿到了数据,不需要提示网络错误,反之提示
if(!self.allBrands || self.allBrands.count == 0){
[weakSelf showError:error]; [weakSelf showError:error];
}
}; };
void(^success)(NSURLSessionDataTask *,KWMBrandsResult *) = ^(NSURLSessionDataTask *task,KWMBrandsResult *result){ void(^success)(NSURLSessionDataTask *,KWMBrandsResult *) = ^(NSURLSessionDataTask *task,KWMBrandsResult *result){
if([weakSelf hasCemaroseError:result]){ if([weakSelf hasCemaroseError:result]){
return ; return ;
} }
if(!self.allBrands){
self.allBrands = result.brands;
}
};
void(^cacheCallback)(KWMBrandsResult *) = ^(KWMBrandsResult *result){
if([weakSelf hasCemaroseError:result]){
return ;
}
self.allBrands = result.brands; self.allBrands = result.brands;
}; };
[self.api getAllBrand:nil success:success failure:failure]; [self.api getAllBrand:nil cacheCallback:cacheCallback success:success failure:failure];
} }
#pragma mark - API BUYClient+Storefront.h #pragma mark - API BUYClient+Storefront.h
...@@ -305,6 +318,11 @@ ...@@ -305,6 +318,11 @@
if(cmodel.brand){ if(cmodel.brand){
[tags addObject:cmodel.brand]; [tags addObject:cmodel.brand];
} }
NSDictionary *parameters = [KWMPPCacheUtil getProductPageCacheKey:cpage pageSize:self.client.pageSize sortOrder:cmodel.sort tags:tags inCollection:cmodel.collection_id];
//从缓存中拿数据
if([self isUseCache:parameters page:cpage cmodel:cmodel]){
return;
}
[self.client getProductsPage:cpage inCollection:cmodel.collection_id withTags:tags sortOrder:cmodel.sort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){ [self.client getProductsPage:cpage inCollection:cmodel.collection_id withTags:tags sortOrder:cmodel.sort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
weakSelf.cvRightProduct.mj_footer.hidden = false; weakSelf.cvRightProduct.mj_footer.hidden = false;
if (cmodel == self.selectedCategory) { if (cmodel == self.selectedCategory) {
...@@ -325,6 +343,8 @@ ...@@ -325,6 +343,8 @@
[weakSelf showError:error]; [weakSelf showError:error];
} }
else{ else{
//保存缓存
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
// weakSelf.refreshUtil.page = page; // weakSelf.refreshUtil.page = page;
cmodel.page = page; cmodel.page = page;
// weakSelf.refreshUtil.hasNextPage = !reachedEnd; // weakSelf.refreshUtil.hasNextPage = !reachedEnd;
...@@ -368,4 +388,30 @@ ...@@ -368,4 +388,30 @@
// [self.cvRightProduct reloadData]; // [self.cvRightProduct reloadData];
} }
#pragma mark -cache
//缓存规则:第一页数据默认先从缓存拿,然后再更新,后面的根据网络判断从缓存拿数据还是从api拿数据
- (BOOL)isUseCache:(NSDictionary *)cacheKeyDictionary page:(NSUInteger)page cmodel:(KWMCategoryModel *)cmodel{
if(!kIsNetwork || page == 1){
NSArray *cacheProducts = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getProductsPage];
if(cacheProducts && cacheProducts.count > 0){
if ([self.cvRightProduct.mj_header isRefreshing]) {
[self.cvRightProduct.mj_header endRefreshing];
}
if ([self.cvRightProduct.mj_footer isRefreshing]) {
[self.cvRightProduct.mj_footer endRefreshing];
}
cmodel.page = page;
if (page == 1) {
[cmodel.products removeAllObjects];
}
[cmodel.products addObjectsFromArray:cacheProducts];
[self.cvRightProduct reloadData];
self.filterTab.userInteractionEnabled = true;
}else if(!kIsNetwork){
[self showToast:CACHE_KEY_FAIL_HINT];
}
}
return !kIsNetwork;
}
@end @end
...@@ -32,6 +32,15 @@ ...@@ -32,6 +32,15 @@
- (void) requestData { - (void) requestData {
[self showLoading]; [self showLoading];
void(^cacheCallback)(id) = ^(id result) {
[self hideLoading];
if (self.type == KWMContentTypePage) {
self.article = [[result pages] firstObject];
}else{
self.article = [[result blogs] firstObject];
}
[self initData];
};
void(^success)(NSURLSessionDataTask *,id) = ^(NSURLSessionDataTask *task, id result) { void(^success)(NSURLSessionDataTask *,id) = ^(NSURLSessionDataTask *task, id result) {
[self hideLoading]; [self hideLoading];
if (self.type == KWMContentTypePage) { if (self.type == KWMContentTypePage) {
...@@ -52,7 +61,7 @@ ...@@ -52,7 +61,7 @@
if (self.type == KWMContentTypePage) { if (self.type == KWMContentTypePage) {
[self.api getAllPage:param success:success failure:failure]; [self.api getAllPage:param success:success failure:failure];
}else{ }else{
[self.api getAllBlog:param success:success failure:failure]; [self.api getAllBlog:param cacheCallback:nil success:success failure:failure];
} }
} }
......
...@@ -96,14 +96,21 @@ ...@@ -96,14 +96,21 @@
//请求api //请求api
- (void)requestBlogAPI{ - (void)requestBlogAPI{
__weak KWMHomeVC *weakSelf = self; __weak KWMHomeVC *weakSelf = self;
[self.api getAllBlog:nil success:^(NSURLSessionDataTask *task, KWMBlogResult *result) { [self.api getAllBlog:nil cacheCallback:^(KWMBlogResult *result) {
if (result != nil) {
_dataArr = [[result.blogs reverseObjectEnumerator] allObjects];
[self.tbvBlog reloadData];
}
} success:^(NSURLSessionDataTask *task, KWMBlogResult *result) {
[weakSelf hideLoading]; [weakSelf hideLoading];
if (result != nil) { if (result != nil) {
_dataArr = [[result.blogs reverseObjectEnumerator] allObjects]; _dataArr = [[result.blogs reverseObjectEnumerator] allObjects];
[self.tbvBlog reloadData]; [self.tbvBlog reloadData];
} }
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
if(self.dataArr==nil || self.dataArr.count == 0){
[self showError:error]; [self showError:error];
}
NSLog(@"error:%@",error); NSLog(@"error:%@",error);
}]; }];
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import <SDWebImage/UIImageView+WebCache.h> #import <SDWebImage/UIImageView+WebCache.h>
#import "MZFormSheetPresentationViewController.h" #import "MZFormSheetPresentationViewController.h"
#import "Buy/Buy.h" #import "Buy/Buy.h"
#import <PPNetworkHelper/PPNetworkCache.h>
@class AppDelegate; @class AppDelegate;
......
...@@ -326,6 +326,12 @@ ...@@ -326,6 +326,12 @@
//显示错误信息 //显示错误信息
- (void)showError:(NSError *)error{ - (void)showError:(NSError *)error{
if (!error){
return;
}
if ([error.domain isEqualToString:@"缓存错误"]){
return;
}
if ([error.domain isEqualToString:NSURLErrorDomain]) { if ([error.domain isEqualToString:NSURLErrorDomain]) {
[self showToast:@"网络已断开,请重新连接"]; [self showToast:@"网络已断开,请重新连接"];
return; return;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<customFonts key="customFonts"> <customFonts key="customFonts">
...@@ -206,6 +206,7 @@ ...@@ -206,6 +206,7 @@
<constraints> <constraints>
<constraint firstItem="u9U-m1-VeK" firstAttribute="centerY" secondItem="0c8-k5-y3n" secondAttribute="centerY" id="25t-Oi-zog"/> <constraint firstItem="u9U-m1-VeK" firstAttribute="centerY" secondItem="0c8-k5-y3n" secondAttribute="centerY" id="25t-Oi-zog"/>
<constraint firstItem="rId-0e-u0H" firstAttribute="trailing" secondItem="0c8-k5-y3n" secondAttribute="trailing" id="75j-Nn-dmV"/> <constraint firstItem="rId-0e-u0H" firstAttribute="trailing" secondItem="0c8-k5-y3n" secondAttribute="trailing" id="75j-Nn-dmV"/>
<constraint firstItem="asr-TI-lDQ" firstAttribute="top" secondItem="aEK-K4-3qL" secondAttribute="bottom" constant="11" id="7nW-oq-nDP"/>
<constraint firstItem="Djf-FZ-FEl" firstAttribute="top" secondItem="HiY-gY-I4h" secondAttribute="bottom" constant="78" id="9tF-dE-M4M"/> <constraint firstItem="Djf-FZ-FEl" firstAttribute="top" secondItem="HiY-gY-I4h" secondAttribute="bottom" constant="78" id="9tF-dE-M4M"/>
<constraint firstAttribute="trailing" secondItem="HiY-gY-I4h" secondAttribute="trailing" constant="44" id="Aaw-WU-fjk"/> <constraint firstAttribute="trailing" secondItem="HiY-gY-I4h" secondAttribute="trailing" constant="44" id="Aaw-WU-fjk"/>
<constraint firstItem="cZA-Am-Uhr" firstAttribute="top" secondItem="aob-ud-437" secondAttribute="bottom" constant="51" id="DAS-0A-mel"/> <constraint firstItem="cZA-Am-Uhr" firstAttribute="top" secondItem="aob-ud-437" secondAttribute="bottom" constant="51" id="DAS-0A-mel"/>
...@@ -215,7 +216,6 @@ ...@@ -215,7 +216,6 @@
<constraint firstItem="aob-ud-437" firstAttribute="centerX" secondItem="ely-f5-Lwm" secondAttribute="centerX" id="KU0-IE-DgX"/> <constraint firstItem="aob-ud-437" firstAttribute="centerX" secondItem="ely-f5-Lwm" secondAttribute="centerX" id="KU0-IE-DgX"/>
<constraint firstItem="0c8-k5-y3n" firstAttribute="centerX" secondItem="ely-f5-Lwm" secondAttribute="centerX" id="Ka8-Ji-nhM"/> <constraint firstItem="0c8-k5-y3n" firstAttribute="centerX" secondItem="ely-f5-Lwm" secondAttribute="centerX" id="Ka8-Ji-nhM"/>
<constraint firstItem="aob-ud-437" firstAttribute="top" secondItem="rId-0e-u0H" secondAttribute="bottom" constant="49" id="NQa-TC-6pa"/> <constraint firstItem="aob-ud-437" firstAttribute="top" secondItem="rId-0e-u0H" secondAttribute="bottom" constant="49" id="NQa-TC-6pa"/>
<constraint firstItem="asr-TI-lDQ" firstAttribute="top" secondItem="ely-f5-Lwm" secondAttribute="top" constant="31" id="OH6-Xy-NVa"/>
<constraint firstItem="rId-0e-u0H" firstAttribute="top" secondItem="0c8-k5-y3n" secondAttribute="bottom" id="Pbi-2f-q1U"/> <constraint firstItem="rId-0e-u0H" firstAttribute="top" secondItem="0c8-k5-y3n" secondAttribute="bottom" id="Pbi-2f-q1U"/>
<constraint firstItem="Mtf-5x-f0v" firstAttribute="top" secondItem="7U8-AN-1tB" secondAttribute="bottom" constant="22" id="QW2-mK-nvw"/> <constraint firstItem="Mtf-5x-f0v" firstAttribute="top" secondItem="7U8-AN-1tB" secondAttribute="bottom" constant="22" id="QW2-mK-nvw"/>
<constraint firstItem="0c8-k5-y3n" firstAttribute="top" secondItem="ely-f5-Lwm" secondAttribute="top" constant="282" id="UTS-0F-XzY"/> <constraint firstItem="0c8-k5-y3n" firstAttribute="top" secondItem="ely-f5-Lwm" secondAttribute="top" constant="282" id="UTS-0F-XzY"/>
......
...@@ -187,9 +187,6 @@ ...@@ -187,9 +187,6 @@
self.client.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]]; self.client.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]];
[self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) { [self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) {
for (int i = 0; i<orders.count; i++) {
NSLog(@"langArray[%d]=%@", i,orders[i].JSONDictionary);
}
[weakSelf hideLoading]; [weakSelf hideLoading];
if (error == nil && orders != nil ) { if (error == nil && orders != nil ) {
[weakSelf.orderList removeAllObjects]; [weakSelf.orderList removeAllObjects];
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#import "KWMWishListVC.h" #import "KWMWishListVC.h"
#import <MJRefresh.h> #import <MJRefresh.h>
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
#import "KWMPPCacheUtil.h"
#import "CacheKeyConstants.h"
typedef enum{ typedef enum{
...@@ -349,12 +351,16 @@ typedef enum{ ...@@ -349,12 +351,16 @@ typedef enum{
[self showLoading]; [self showLoading];
BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"]; BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"];
NSInteger cpage = isHome ? self.page : 1; NSInteger cpage = isHome ? self.page : 1;
NSDictionary *parameters = [self getProductCacheKeyDictionary:cpage tags:tags handle:handle];
if([self isUseProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome]){
return;
}
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) { [self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
[self hideLoading];
if (!error) { if (!error) {
[self.client getProductsPage:cpage inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) { [self.client getProductsPage:cpage inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
[self hideLoading];
if (!error) { if (!error) {
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage products:products];
[self setValue:products forKeyPath:valueKeyPath]; [self setValue:products forKeyPath:valueKeyPath];
[self.cvHome reloadData]; [self.cvHome reloadData];
}else{ }else{
...@@ -366,7 +372,6 @@ typedef enum{ ...@@ -366,7 +372,6 @@ typedef enum{
} }
}]; }];
}else{ }else{
[self hideLoading];
[self showError:error]; [self showError:error];
} }
}]; }];
...@@ -392,7 +397,11 @@ typedef enum{ ...@@ -392,7 +397,11 @@ typedef enum{
- (void) loadHomeData { - (void) loadHomeData {
[self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"recommendHeader.productArray"]; [self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"recommendHeader.productArray"];
if([self isUseHomeDataCache]){
return;
}
[self.api getHomeDataWithSuccess:^(NSURLSessionDataTask *task, KWMHomeDataResult *result) { [self.api getHomeDataWithSuccess:^(NSURLSessionDataTask *task, KWMHomeDataResult *result) {
[KWMPPCacheUtil saveDataToCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess homeData:result.data];
self.homeData = result.data; self.homeData = result.data;
[self.cvHome reloadData]; [self.cvHome reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
...@@ -442,4 +451,57 @@ typedef enum{ ...@@ -442,4 +451,57 @@ typedef enum{
} }
#pragma mark -cache
/** 因为homedata api的url是动态的,url上的时间戳随时间的改变,所以需要手动保存,和获取 **/
-(BOOL)isUseHomeDataCache{
if(!kIsNetwork){
KWMHomeData *homeData = [KWMPPCacheUtil getHomeDataByCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess];
if(homeData){
self.homeData = homeData;
[self.cvHome reloadData];
}else{
[self showToast:CACHE_KEY_FAIL_HINT];
}
}
return !kIsNetwork;
}
//初始化缓存parameters key
- (NSDictionary *)getProductCacheKeyDictionary:(NSUInteger)page
tags:(nullable NSArray <NSString *> *)tags
handle:(nullable NSString *)handle{
NSMutableDictionary *params = @{
@"limit" : @(self.client.pageSize),
@"page" : @(page)
}.mutableCopy;
if (tags) {
params[@"tag"] = [tags componentsJoinedByString:@","];
}
if (handle) {
params[@"handle"] = handle;
}
return params;
}
-(BOOL)isUseProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page isHome:(BOOL)isHome{
if(!kIsNetwork){
[self hideLoading];
NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
if(products && products.count > 0){
[self setValue:products forKeyPath:valueKeyPath];
[self.cvHome reloadData];
if (isHome) {
self.page = self.page + 1;
products.count ? [self.cvHome.mj_footer endRefreshing] : [self.cvHome.mj_footer endRefreshingWithNoMoreData];
}
}else{
[self showToast:CACHE_KEY_FAIL_HINT];
if (isHome) {
[self.cvHome.mj_footer endRefreshing];
}
}
}
return !kIsNetwork;
}
@end @end
...@@ -61,12 +61,12 @@ ...@@ -61,12 +61,12 @@
@implementation KWMFirstDetailView @implementation KWMFirstDetailView
- (id)init{ //- (id)init{
if (self=[super init]){ // if (self=[super init]){
[self addView]; // [self addView];
} // }
return self; // return self;
} //}
- (id)initWithCoder:(NSCoder *)aDecoder { - (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder]; self = [super initWithCoder:aDecoder];
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
NSLog(@"KWMProductDetailView%f%f",self.frame.size.width,self.frame.size.height); NSLog(@"KWMProductDetailView%f%f",self.frame.size.width,self.frame.size.height);
self.vView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); self.vView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self addSubview:self.vView]; [self addSubview:self.vView];
self.imageScrollView.autoScroll = false;
self.imageScrollView.pageDotImage = [UIImage imageNamed:@"ic_page_1"]; self.imageScrollView.pageDotImage = [UIImage imageNamed:@"ic_page_1"];
self.imageScrollView.currentPageDotImage = [UIImage imageNamed:@"ic_page_2"]; self.imageScrollView.currentPageDotImage = [UIImage imageNamed:@"ic_page_2"];
self.imageScrollView.delegate = self; self.imageScrollView.delegate = self;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "KWMNewProductVC.h" #import "KWMNewProductVC.h"
#import "KWMLoginVC.h" #import "KWMLoginVC.h"
#import "KWMBeforePayVC.h" #import "KWMBeforePayVC.h"
#import "KWMContactUsVC.h"
#import "KWMBrandCaramelVC.h" #import "KWMBrandCaramelVC.h"
#import "KWMShareVC.h" #import "KWMShareVC.h"
#import "KWMWishListVC.h" #import "KWMWishListVC.h"
...@@ -32,6 +33,10 @@ ...@@ -32,6 +33,10 @@
@property (weak, nonatomic) IBOutlet UIButton *btnShopCart; @property (weak, nonatomic) IBOutlet UIButton *btnShopCart;
@property (weak, nonatomic) IBOutlet UIButton *btnContactUs;
@property (weak, nonatomic) IBOutlet UIView *vBottomBar;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIButton *btnLike; @property (weak, nonatomic) IBOutlet UIButton *btnLike;
...@@ -102,7 +107,9 @@ ...@@ -102,7 +107,9 @@
self.detailView1.delegate = self; self.detailView1.delegate = self;
self.detailView2.delegate = self; self.detailView2.delegate = self;
self.midDetailView.delegate = self; self.midDetailView.delegate = self;
[self initBottomViewHidden];
if(self.product){ if(self.product){
[self.detailView1 setSizeGuideHidden:!self.typeTag];
self.midDetailView.product = self.product; self.midDetailView.product = self.product;
[self.detailView1 setData:self.product]; [self.detailView1 setData:self.product];
[self requestBrandProducts:1]; [self requestBrandProducts:1];
...@@ -119,6 +126,18 @@ ...@@ -119,6 +126,18 @@
} }
-(void)initBottomViewHidden{
if(self.product){
NSString *productVendor = self.product.vendor;
NSString *targetVendor = @"Moncler";
BOOL isShowContactUs = [productVendor isEqualToString:targetVendor];
self.vBottomBar.hidden = isShowContactUs;
self.btnContactUs.hidden = !isShowContactUs;
self.vBottomBar.hidden = NO;
}
}
- (void)initShopCartCount{ - (void)initShopCartCount{
...@@ -187,6 +206,11 @@ ...@@ -187,6 +206,11 @@
[self.navigationController pushViewController:shopCartVC animated:YES]; [self.navigationController pushViewController:shopCartVC animated:YES];
} }
-(IBAction)onClickContactUs:(id)sender{
KWMContactUsVC *contactVC = (KWMContactUsVC *)[KWMBaseVC findControllerBy:[KWMContactUsVC kwmTag] fromStoryboard:@"Mine"];
[self.navigationController pushViewController:contactVC animated:YES];
}
-(IBAction)onClickShare:(id)sender{ -(IBAction)onClickShare:(id)sender{
if(self.product){ if(self.product){
KWMShareVC *shareVC = (KWMShareVC *)[KWMBaseVC findControllerBy:[KWMShareVC kwmTag] fromStoryboard:@"New"]; KWMShareVC *shareVC = (KWMShareVC *)[KWMBaseVC findControllerBy:[KWMShareVC kwmTag] fromStoryboard:@"New"];
...@@ -493,15 +517,16 @@ ...@@ -493,15 +517,16 @@
}else if(product){ }else if(product){
weakSelf.product = product; weakSelf.product = product;
weakSelf.productId = product.identifier; weakSelf.productId = product.identifier;
[weakSelf initBottomViewHidden];
// [weakSelf initMidViewHight]; // [weakSelf initMidViewHight];
weakSelf.midDetailView.product = product; weakSelf.midDetailView.product = product;
[weakSelf.detailView1 setData:product]; [weakSelf.detailView1 setData:product];
[self requestBrandProducts:1]; [weakSelf requestBrandProducts:1];
[self requestCategoryProducts:1]; [weakSelf requestCategoryProducts:1];
//handle初始化的商品页面还没有请求admin api(获取库存),以及颜色 api;
if(self.handle){ if(weakSelf.handle){
[self requestAdminProduct]; [weakSelf requestAdminProduct];
[self requestColorMetafield]; [weakSelf requestColorMetafield];
} }
} }
}; };
...@@ -741,7 +766,6 @@ ...@@ -741,7 +766,6 @@
break; break;
} }
} }
[self.detailView1 setSizeGuideHidden:!self.typeTag]; [self.detailView1 setSizeGuideHidden:!self.typeTag];
} }
......
...@@ -130,6 +130,20 @@ ...@@ -130,6 +130,20 @@
<constraint firstItem="2KH-pA-K5l" firstAttribute="height" secondItem="T6J-Gp-5iu" secondAttribute="width" constant="250" id="pFo-pT-vgh"/> <constraint firstItem="2KH-pA-K5l" firstAttribute="height" secondItem="T6J-Gp-5iu" secondAttribute="width" constant="250" id="pFo-pT-vgh"/>
</constraints> </constraints>
</scrollView> </scrollView>
<button opaque="NO" tag="999" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="344-t8-DPO">
<rect key="frame" x="0.0" y="617" width="375" height="50"/>
<color key="backgroundColor" red="0.14117647059999999" green="0.14117647059999999" blue="0.14117647059999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="EXc-qM-375"/>
</constraints>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="15"/>
<state key="normal" title="CONTACT US">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onClickContactUs:" destination="Vzq-D6-e57" eventType="touchUpInside" id="0G8-We-IP4"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aqB-2y-BKU" userLabel="底部"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aqB-2y-BKU" userLabel="底部">
<rect key="frame" x="0.0" y="617" width="375" height="50"/> <rect key="frame" x="0.0" y="617" width="375" height="50"/>
<subviews> <subviews>
...@@ -223,17 +237,21 @@ ...@@ -223,17 +237,21 @@
<constraints> <constraints>
<constraint firstAttribute="trailing" secondItem="aqB-2y-BKU" secondAttribute="trailing" id="2B4-2I-dss"/> <constraint firstAttribute="trailing" secondItem="aqB-2y-BKU" secondAttribute="trailing" id="2B4-2I-dss"/>
<constraint firstItem="kgb-zB-eBa" firstAttribute="top" secondItem="Pjy-Ny-sa9" secondAttribute="bottom" id="3J0-tF-Mna"/> <constraint firstItem="kgb-zB-eBa" firstAttribute="top" secondItem="Pjy-Ny-sa9" secondAttribute="bottom" id="3J0-tF-Mna"/>
<constraint firstAttribute="trailing" secondItem="344-t8-DPO" secondAttribute="trailing" id="4Nw-O8-AnE"/>
<constraint firstItem="aqB-2y-BKU" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="6I6-ul-bGF"/> <constraint firstItem="aqB-2y-BKU" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="6I6-ul-bGF"/>
<constraint firstAttribute="trailing" secondItem="T6J-Gp-5iu" secondAttribute="trailing" id="B5K-Fj-FOR"/> <constraint firstAttribute="trailing" secondItem="T6J-Gp-5iu" secondAttribute="trailing" id="B5K-Fj-FOR"/>
<constraint firstItem="T6J-Gp-5iu" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="DZE-DY-3SX"/> <constraint firstItem="T6J-Gp-5iu" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="DZE-DY-3SX"/>
<constraint firstItem="5rs-FM-Imo" firstAttribute="top" secondItem="aqB-2y-BKU" secondAttribute="bottom" id="Dag-cY-cd9"/> <constraint firstItem="5rs-FM-Imo" firstAttribute="top" secondItem="aqB-2y-BKU" secondAttribute="bottom" id="Dag-cY-cd9"/>
<constraint firstAttribute="trailing" secondItem="kgb-zB-eBa" secondAttribute="trailing" id="FyY-BZ-73X"/> <constraint firstAttribute="trailing" secondItem="kgb-zB-eBa" secondAttribute="trailing" id="FyY-BZ-73X"/>
<constraint firstItem="kgb-zB-eBa" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="KfD-qL-WSj"/> <constraint firstItem="kgb-zB-eBa" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="KfD-qL-WSj"/>
<constraint firstItem="344-t8-DPO" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="Vt4-dE-ATW"/>
<constraint firstItem="aqB-2y-BKU" firstAttribute="top" secondItem="T6J-Gp-5iu" secondAttribute="bottom" id="kEG-am-iPo"/> <constraint firstItem="aqB-2y-BKU" firstAttribute="top" secondItem="T6J-Gp-5iu" secondAttribute="bottom" id="kEG-am-iPo"/>
<constraint firstItem="5rs-FM-Imo" firstAttribute="top" secondItem="344-t8-DPO" secondAttribute="bottom" id="m3x-3k-Osi"/>
<constraint firstItem="T6J-Gp-5iu" firstAttribute="top" secondItem="Pjy-Ny-sa9" secondAttribute="bottom" constant="44" id="nNS-e6-C1V"/> <constraint firstItem="T6J-Gp-5iu" firstAttribute="top" secondItem="Pjy-Ny-sa9" secondAttribute="bottom" constant="44" id="nNS-e6-C1V"/>
</constraints> </constraints>
</view> </view>
<connections> <connections>
<outlet property="btnContactUs" destination="344-t8-DPO" id="Se8-h5-pev"/>
<outlet property="btnLike" destination="jLv-Vv-7Vi" id="sep-kb-Y2L"/> <outlet property="btnLike" destination="jLv-Vv-7Vi" id="sep-kb-Y2L"/>
<outlet property="btnShopCart" destination="gbx-rg-A8B" id="vel-Ab-0rI"/> <outlet property="btnShopCart" destination="gbx-rg-A8B" id="vel-Ab-0rI"/>
<outlet property="detailView1" destination="2KH-pA-K5l" id="ynO-by-UfZ"/> <outlet property="detailView1" destination="2KH-pA-K5l" id="ynO-by-UfZ"/>
...@@ -242,6 +260,7 @@ ...@@ -242,6 +260,7 @@
<outlet property="heightMidView" destination="Pwf-vg-Z3k" id="h8Z-Kr-bXi"/> <outlet property="heightMidView" destination="Pwf-vg-Z3k" id="h8Z-Kr-bXi"/>
<outlet property="midDetailView" destination="t55-gT-VGG" id="BRI-de-9Jz"/> <outlet property="midDetailView" destination="t55-gT-VGG" id="BRI-de-9Jz"/>
<outlet property="scrollView" destination="T6J-Gp-5iu" id="ZLc-Xh-Pyk"/> <outlet property="scrollView" destination="T6J-Gp-5iu" id="ZLc-Xh-Pyk"/>
<outlet property="vBottomBar" destination="aqB-2y-BKU" id="S6H-fL-0uE"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="uHF-Hi-PUR" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="uHF-Hi-PUR" userLabel="First Responder" sceneMemberID="firstResponder"/>
......
...@@ -41,7 +41,8 @@ ...@@ -41,7 +41,8 @@
*/ */
@property (strong, nonatomic) NSArray<NSString *>*ctags; @property (strong, nonatomic) NSArray<NSString *>*ctags;
@property (nonatomic) KWMProductType *productType; /** 该属性相关页面已经废弃,相关逻辑也已删除 **/
@property (nonatomic) KWMProductType *productType DEPRECATED_ATTRIBUTE;
@property (nonatomic) BUYCollectionSort collectionSort; @property (nonatomic) BUYCollectionSort collectionSort;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#import "KWMFilterUtil.h" #import "KWMFilterUtil.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
#import "KWMImageBlurUtil.h" #import "KWMImageBlurUtil.h"
#import "KWMPPCacheUtil.h"
@interface KWMSelectedGoodsVC () @interface KWMSelectedGoodsVC ()
@end @end
...@@ -55,22 +56,6 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -55,22 +56,6 @@ static NSString *idStr = @"KWMBrandCaramelCell";
self.collectionSort = BUYCollectionSortCreatedDescending; self.collectionSort = BUYCollectionSortCreatedDescending;
if (self.handle && !self.title) { if (self.handle && !self.title) {
self.title = self.handle.capitalizedString; self.title = self.handle.capitalizedString;
}else if(self.productType != nil){
//初始化双行标题栏
NSString *mTitle;
if(self.tagType == 0){
mTitle = @"婴儿";
}else if(self.tagType == 1){
mTitle = @"女孩";
}else if(self.tagType == 2){
mTitle = @"男孩";
}else if(self.tagType == 3){
mTitle = @"鞋子";
}
KWMDoubleTitleView *doubleTitleView = [[KWMDoubleTitleView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
doubleTitleView.lbTitle.text = mTitle;
doubleTitleView.lbSecondTitle.text = self.productType.value;
self.navigationItem.titleView=doubleTitleView;
} }
openPosition = -1; openPosition = -1;
self.automaticallyAdjustsScrollViewInsets = NO; self.automaticallyAdjustsScrollViewInsets = NO;
...@@ -83,32 +68,10 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -83,32 +68,10 @@ static NSString *idStr = @"KWMBrandCaramelCell";
self.filterView.delegate = self; self.filterView.delegate = self;
self.filterTab.delegate = self; self.filterTab.delegate = self;
[self initCacheData]; [self fixFilterError];
} }
-(void)initCacheData{ -(void)fixFilterError{
NSNumber *collectionId;
NSArray *tags;
if(self.collection!=nil){
collectionId = self.collection.identifier;
}
if(self.productType!=nil){
if(![KWMStringUtil isEmpty:self.productType.collectionId]){
NSInteger num = [self.productType.collectionId integerValue];
collectionId = @(num);
}
NSString *tag;
if(self.tagType == 0){
tag = @"baby";
}else if(self.tagType == 1){
tag = @"girls";
}else if(self.tagType == 2){
tag = @"boys";
}else if(self.tagType == 3){
tag = @"shoes";
}
tags = [NSArray arrayWithObjects:tag, nil];
}
NSMutableDictionary *sf = [NSMutableDictionary new]; NSMutableDictionary *sf = [NSMutableDictionary new];
for (NSString *tag in self.ctags) { for (NSString *tag in self.ctags) {
...@@ -139,12 +102,6 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -139,12 +102,6 @@ static NSString *idStr = @"KWMBrandCaramelCell";
return r; return r;
}] mutableCopy]]; }] mutableCopy]];
} }
NSArray *products = [self.userDao getCollectionCache:collectionId tags:tags];
if(products && products.count>0){
[self appendDataList:products setPage:1];
self.currentPage = 0;
}
} }
-(UITableView *)targetTableView{ -(UITableView *)targetTableView{
...@@ -274,20 +231,51 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -274,20 +231,51 @@ static NSString *idStr = @"KWMBrandCaramelCell";
- (void)requestProductList{ - (void)requestProductList{
__weak KWMSelectedGoodsVC *weakSelf = self; __weak KWMSelectedGoodsVC *weakSelf = self;
if (self.handle) {
[self.client getCollectionByHandle:self.handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
NSArray * tags = [KWMFilterUtil getTagsByFilterArray:weakSelf.filterView.selectedTags];
if ([tags count] <= 0) {
tags = weakSelf.ctags;
}
if(error){
[weakSelf showError:error];
}
if(collection){
[weakSelf requestProductListApi:collection.identifier tags:tags];
}
}];
return;
}else{
if(!self.collection){
return;
}
NSNumber *collectionId = self.collection.identifier;
//初始化tag
NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:self.filterView.selectedTags];
if(collectionId == nil){
return;
}
[self requestProductListApi:collectionId tags:tags];
}
}
- (void)requestProductListApi:(NSNumber *)collectionId tags:(NSArray *)tags{
self.isLoading = YES;
__weak KWMSelectedGoodsVC *weakSelf = self;
NSInteger tagetPage = self.currentPage.integerValue + 1; NSInteger tagetPage = self.currentPage.integerValue + 1;
void(^completion)(NSArray<BUYProduct *> *,NSUInteger,BOOL,NSError*) = ^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){ BUYCollectionSort collectionSort = self.filterView.selectedSort;
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
[weakSelf hideLoading]; [weakSelf hideLoading];
weakSelf.isLoading = NO;
if(tagetPage == 1){ if(tagetPage == 1){
if(!products || products.count == 0){
self.vNoData.hidden = NO;
[weakSelf.dataList removeAllObjects]; [weakSelf.dataList removeAllObjects];
if(!products || products.count == 0){
weakSelf.vNoData.hidden = NO;
[weakSelf.tbvSelectedGoods reloadData]; [weakSelf.tbvSelectedGoods reloadData];
return; return;
} }
} }
weakSelf.isLoading = NO;
if (error == nil && products) { if (error == nil && products) {
self.vNoData.hidden = YES; self.vNoData.hidden = YES;
weakSelf.hasNextPage = !reachedEnd; weakSelf.hasNextPage = !reachedEnd;
...@@ -297,51 +285,7 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -297,51 +285,7 @@ static NSString *idStr = @"KWMBrandCaramelCell";
[self showError:error]; [self showError:error];
NSLog(@"Error fetching products: %@", error); NSLog(@"Error fetching products: %@", error);
} }
};
if (self.handle) {
[self.client getCollectionByHandle:self.handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
NSArray * tags = [KWMFilterUtil getTagsByFilterArray:self.filterView.selectedTags];
if ([tags count] <= 0) {
tags = self.ctags;
}
[self.client getProductsPage:tagetPage inCollection:collection.identifier withTags:tags sortOrder:self.filterView.selectedSort completion:completion];
}]; }];
// [self.client getProductsPage:tagetPage inCollection:nil withTags:self.ctags sortOrder:self.filterView.selectedSort completion:completion];
return;
}
NSNumber *collectionId;
if(self.collection!=nil){
collectionId = self.collection.identifier;
}
//初始化排序及筛选tag
BUYCollectionSort collectionSort = self.filterView.selectedSort;
NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:self.filterView.selectedTags];
if(self.productType!=nil){
if(![KWMStringUtil isEmpty:self.productType.collectionId]){
NSInteger num = [self.productType.collectionId integerValue];
collectionId = @(num);
}
if(self.tagType == 0){
[tags addObject:@"baby"];
}else if(self.tagType == 1){
[tags addObject:@"girls"];
}else if(self.tagType == 2){
[tags addObject:@"boys"];
}else if(self.tagType == 3){
[tags addObject:@"shoes"];
}
}
if(collectionId == nil){
return;
}
self.isLoading = YES;
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:completion];
} }
@end @end
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
-(MJRefreshHeader *)createHeader{ -(MJRefreshHeader *)createHeader{
__weak KWMCollectionRefreshUtil *weakSelf = self; __weak KWMCollectionRefreshUtil *weakSelf = self;
KWMLoadingHeader *header = [KWMLoadingHeader headerWithRefreshingBlock:^{ KWMLoadingHeader *header = [KWMLoadingHeader headerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf reLoadData]; [weakSelf reLoadData];
}); });
}]; }];
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
__weak KWMCollectionRefreshUtil *weakSelf = self; __weak KWMCollectionRefreshUtil *weakSelf = self;
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf loadData]; [weakSelf loadData];
}); });
}]; }];
......
//
// KWMPPCacheUtil.h
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "KWMHomeData.h"
#import <Buy/Buy.h>
#import "CacheKeyConstants.h"
@interface KWMPPCacheUtil : NSObject
//这个key用的地方比较多,所以抽在这里了
+ (NSDictionary *)getProductPageCacheKey:(NSUInteger)page
pageSize:(NSUInteger)pageSize
sortOrder:(BUYCollectionSort)sortOrder
tags:(nullable NSArray <NSString *> *)tags
inCollection:(nullable NSNumber *)collectionId;
+ (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products;
+ (NSArray *)getProductDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey homeData:(KWMHomeData *)homeData;
+(KWMHomeData *)getHomeDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey collection:(BUYCollection *)collection;
+(BUYCollection *)getCollectionByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
@end
//
// KWMPPCacheUtil.m
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMPPCacheUtil.h"
@implementation KWMPPCacheUtil
#pragma mark -cache
//这个key用的地方比较多,所以抽在这里了
+ (NSDictionary *)getProductPageCacheKey:(NSUInteger)page
pageSize:(NSUInteger)pageSize
sortOrder:(BUYCollectionSort)sortOrder
tags:(nullable NSArray <NSString *> *)tags
inCollection:(nullable NSNumber *)collectionId{
NSMutableDictionary *params = @{
@"limit" : @(pageSize),
@"page" : @(page),
@"sort_by" : [BUYCollection sortOrderParameterForCollectionSort:sortOrder]
}.mutableCopy;
if (tags) {
params[@"tag"] = [tags componentsJoinedByString:@","];
}
if (collectionId) {
params[@"collection_id"] = collectionId;
}
return params;
}
+ (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products{
NSMutableArray *dictArray = [NSMutableArray array];
if(products){
for(BUYProduct *product in products){
NSDictionary *productDict = product.JSONDictionary;
if(productDict){
[dictArray addObject:productDict];
}
}
}
NSDictionary *saveDict = [[NSDictionary alloc] initWithObjectsAndKeys:dictArray, @"array",nil];
[PPNetworkCache setHttpCache:saveDict URL:urlKey parameters:cacheKeyDictionary];
}
+ (NSArray *)getProductDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey{
NSDictionary *cacheDictionary = [PPNetworkCache httpCacheForURL:urlKey parameters:cacheKeyDictionary];
NSMutableArray *products = [NSMutableArray array];
if(cacheDictionary && [cacheDictionary objectForKey:@"array"]){
NSArray *dictArray = [cacheDictionary objectForKey:@"array"];
for(NSDictionary *dict in dictArray){
if(dict){
BUYProduct *product = (BUYProduct *)[[BUYModelManager modelManager] buy_objectWithEntityName:[BUYProduct entityName] JSONDictionary:dict];
[products addObject:product];
}
}
}
return products;
}
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey homeData:(KWMHomeData *)homeData{
NSDictionary *saveDict = [[NSDictionary alloc]initWithObjectsAndKeys:homeData,@"homeData", nil];
[PPNetworkCache setHttpCache:saveDict URL:urlKey parameters:cacheKeyDictionary];
}
+(KWMHomeData *)getHomeDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey{
NSDictionary *cacheDictionary = [PPNetworkCache httpCacheForURL:urlKey parameters:cacheKeyDictionary];
if(cacheDictionary && [cacheDictionary objectForKey:@"homeData"]){
KWMHomeData *homeData = (KWMHomeData *)[cacheDictionary objectForKey:@"homeData"];
return homeData;
}else{
return nil;
}
}
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey collection:(BUYCollection *)collection{
// if(collection && collection.JSONDictionary){
//这里会崩溃,因为collection的image(BuyImageLink里又有一个Collection,获取其dictionary会出现无限递归的问题)
// NSDictionary *saveDict = collection.JSONDictionary;
// [PPNetworkCache setHttpCache:saveDict URL:urlKey parameters:cacheKeyDictionary];
// }
if(collection){
NSString *imageString = collection.image.sourceURL.absoluteString;
NSDictionary *collectionData = @{@"image":imageString,
@"identifier":collection.identifier.stringValue,
@"description":collection.htmlDescription,
};
[PPNetworkCache setHttpCache:collectionData URL:urlKey parameters:cacheKeyDictionary];
}
}
+(BUYCollection *)getCollectionByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey{
NSDictionary *cacheDictionary = [PPNetworkCache httpCacheForURL:urlKey parameters:cacheKeyDictionary];
if(cacheDictionary){
// BUYCollection *collection = (BUYCollection *)[[BUYModelManager modelManager] buy_objectWithEntityName:[BUYCollection entityName] JSONDictionary:cacheDictionary];
// return collection;
BUYCollection *collection = [[BUYCollection alloc]init];
collection.image = [[BUYImageLink alloc]init];
NSString *imageString = cacheDictionary[@"image"];
collection.image.sourceURL = [[NSURL alloc]initWithString:imageString];
collection.htmlDescription = cacheDictionary[@"description"];
NSString *idString = cacheDictionary[@"identifier"];
collection.identifier = @([idString integerValue]);
return collection;
}else{
return nil;
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment