Commit a0c4c6fe by lee

u

parent b980ca24
......@@ -14,7 +14,8 @@ pod 'SAMKeychain'
pod 'RXCollections','~> 1.0'
pod 'TOWebViewController'
pod 'AFNetworking','~> 3.1'
#pod 'AFNetworking','~> 3.1'
pod 'PPNetworkHelper'
pod 'JSONModel','~> 1.2.0'
pod 'SDWebImage','~> 3.7.1'
pod 'SAMCategories', '~> 0.5.1'
......
......@@ -21,6 +21,8 @@
@property (weak, nonatomic) id<KWMProductDetailViewDelegate>delegate;
@property (weak, nonatomic) IBOutlet UIButton *sizeGuide;
-(void)setData:(BUYProduct *)product;
@end
......@@ -20,6 +20,7 @@
<outlet property="lbPrice" destination="gpT-Sg-ghu" id="FGd-AA-Yiv"/>
<outlet property="lbUnit" destination="wfT-JC-g9d" id="MSn-kd-aQ2"/>
<outlet property="pageControl" destination="M6v-TN-2WE" id="QPe-TI-LdG"/>
<outlet property="sizeGuide" destination="EM9-Ay-Qxk" id="4Dh-eU-qhb"/>
<outlet property="vView" destination="iN0-l3-epB" id="TQD-W9-jEg"/>
</connections>
</placeholder>
......
......@@ -27,6 +27,7 @@
#import <TOWebViewController/TOWebViewController.h>
#import <AFNetworking/AFNetworking.h>
#import <TOWebViewController/NJKWebViewProgress.h>
#import <PPNetworkHelper/PPNetworkHelper.h>
@interface KWMProductDetailVC ()<KWMBottomViewDelegate,KWMProductDetailViewDelegate,KWMSelectSizeVCDelegate,UIScrollViewDelegate>
......@@ -41,6 +42,8 @@
@property (nonatomic) BUYCollection *collectionSameBrand;
@property (nonatomic) NSString *typeTag;
@property (weak, nonatomic) IBOutlet UIButton *btnShopCart;
@property (weak, nonatomic) IBOutlet UIButton *btnShare;
......@@ -64,6 +67,16 @@
if(self.product && self.product.identifier && !self.product.JSONDictionary){
[self getProductBy:nil product:self.product];
}
NSArray *types = @[@"baby",@"girls",@"boys",@"shoes",@"newborn"];
for (NSString *tag in self.product.tags) {
if ([types containsObject:tag.lowercaseString]) {
self.typeTag = tag.lowercaseString;
break;
}
}
if (!self.typeTag) {
self.productDetailView.sizeGuide.hidden = YES;
}
}
- (BOOL)prefersStatusBarHidden {
......@@ -110,41 +123,61 @@
- (void)kwm_onClickSizeGuide {
NSString *brand = [self.product.vendor stringByReplacingOccurrencesOfRegex:@"\\s*\\W\\s*" withString:@"-"].lowercaseString;
NSString *type = @"";
NSArray *types = @[@"baby",@"girls",@"boys",@"shoes"];
for (NSString *tag in self.product.tags) {
if ([types containsObject:tag.lowercaseString]) {
type = tag.lowercaseString;
break;
}
}
// NSString *url= [NSString stringWithFormat:@"https://cemarose.myshopify.com/pages/%@-size-guide-%@",brand,type];
NSString *baseUrl = @"http://www.cemarose.cn/pages/";
NSString *url= [NSString stringWithFormat:@"%@%@-size-guide-%@",baseUrl,brand,type];
NSString *url= [NSString stringWithFormat:@"%@%@-size-guide-%@",baseUrl,brand,self.typeTag];
NSLog(@"size guide url: %@",url);
// TOWebViewController *wv = [[TOWebViewController alloc] initWithURLString:url];
TOWebViewController *wv = [[TOWebViewController alloc] init];
__unused id _ = wv.view;
wv.showPageTitles = NO;
wv.title = @"Size Guide";
wv.navigationButtonsHidden = YES;
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
// manager.responseSerializer = [AFXMLParserResponseSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
[manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
// NJKWebViewProgress *wvp = [vc valueForKeyPath:@"progressManager"];
// [wvp.progressDelegate webViewProgress:wvp updateProgress:downloadProgress.fractionCompleted];
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *body = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
body = [NSString stringWithFormat:@"<meta name='viewport' content='width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no'/><style type='text/css'>"
@".main-header-wrap,.main-footer,.doubly-float{display:none}"
// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//// manager.responseSerializer = [AFXMLParserResponseSerializer serializer];
// manager.responseSerializer = [AFHTTPResponseSerializer serializer];
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
// [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
//// NJKWebViewProgress *wvp = [vc valueForKeyPath:@"progressManager"];
//// [wvp.progressDelegate webViewProgress:wvp updateProgress:downloadProgress.fractionCompleted];
// } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// NSString *body = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
// body = [body stringByReplacingOccurrencesOfRegex:@"<meta[\\w\\W]*?/?>" withString:@""];
// body = [body stringByReplacingOccurrencesOfRegex:@"<script[\\w\\W]*?</script>" withString:@""];
// body = [body stringByReplacingOccurrencesOfRegex:@"<header[\\w\\W]*?</header>" withString:@""];
// body = [body stringByReplacingOccurrencesOfRegex:@"<footer[\\w\\W]*?</footer>" withString:@""];
// body = [body stringByReplacingOccurrencesOfRegex:@"<head>" withString:@"<head><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\" /><style type='text/css'>"
// @".page-title h1.label{font-size:17px;}"
// @".rte.text-content td{padding-left:10px;}"
// @"</style>"];
// [wv.webView loadHTMLString:body baseURL:[NSURL URLWithString:baseUrl]];
// } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// }];
void(^success)(id) = ^(id body){
if (!body) {
return;
}
body = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
body = [body stringByReplacingOccurrencesOfRegex:@"<meta[\\w\\W]*?/?>" withString:@""];
body = [body stringByReplacingOccurrencesOfRegex:@"<script[\\w\\W]*?</script>" withString:@""];
body = [body stringByReplacingOccurrencesOfRegex:@"<header[\\w\\W]*?</header>" withString:@""];
body = [body stringByReplacingOccurrencesOfRegex:@"<footer[\\w\\W]*?</footer>" withString:@""];
body = [body stringByReplacingOccurrencesOfRegex:@"<head>" withString:@"<head><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\" /><style type='text/css'>"
@".page-title h1.label{font-size:17px;}"
@".rte.text-content td{padding-left:10px;}"
@"</style>%@",body];
@"</style>"];
[wv.webView loadHTMLString:body baseURL:[NSURL URLWithString:baseUrl]];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
};
__weak typeof(self) this = self;
[PPNetworkHelper setAFHTTPSessionManagerProperty:^(AFHTTPSessionManager *sessionManager) {
sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
}];
[PPNetworkHelper GET:url parameters:nil responseCache:success success:success failure:^(NSError *error) {
[this showError:error];
}];
[self.navigationController pushViewController:wv animated:YES];
__unused id _ = wv.view;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(200 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
NJKWebViewProgress *wvp = [wv valueForKeyPath:@"progressManager"];
[wvp.progressDelegate webViewProgress:wvp updateProgress:0.1];
......
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