//
// detailWebViewController.m
// BJ
//
// Created by shirenfeng on 16/11/6.
// Copyright © 2016年 com.wsb123. All rights reserved.
// 浏览器
#import "detailWebViewController.h"
#import "DBStrore.h"
#import "BaseSVRRequestOperator.h"
#import "Utilities.h"
#import "FTMacro.h"
#import "AppDelegate.h"
#import "HttpConnect.h"
#import<CommonCrypto/CommonDigest.h>
@interface detailWebViewController ()<UIWebViewDelegate> @property (nonatomic, strong) UIButton *capPicBtn;
@property (nonatomic, strong) UIButton *shopName;
@property (nonatomic, strong) UIButton *mReloadBtn;
@property (nonatomic, strong) UIWebView *mWebView;
@property (nonatomic, strong) BaseSVRRequestOperator *netWorking;
@property (nonatomic, strong) NSMutableArray *clientArray;
@property (nonatomic,strong) NSString *loadedURL;
#define MAXCOUNT 30
#define MAXTIMEOUT 10
@end @implementation detailWebViewController - (void)viewDidLoad {
[super viewDidLoad]; //_shopName.frame = CGRectMake((kScreenWidth-100)/2,11,100,30);
// _capPicBtn.frame = CGRectMake(kScreenWidth-80,11,80,30); // Do any additional setup after loading the view from its nib.
// self.navigationController.navigationBarHidden = NO; [self initview]; }
-(void)initview
{
for(UIView *view in [self.view subviews])
{
[view removeFromSuperview];
} NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *shopname = [defaults stringForKey:@"shopnamedata"]; UIButton *returnTextBtn = [[UIButton alloc] initWithFrame:CGRectMake(,,,)];
[returnTextBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[returnTextBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[returnTextBtn setTitle:[NSString stringWithFormat:@"返回“选123”"] forState: UIControlStateNormal];
returnTextBtn.backgroundColor = [UIColor clearColor];
[returnTextBtn setTitleColor:self.view.tintColor forState:UIControlStateNormal];
returnTextBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[returnTextBtn addTarget:self action:@selector(returnApp) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:returnTextBtn]; _shopName = [[UIButton alloc] initWithFrame:CGRectMake((kScreenWidth-)/,,,)];
[_shopName setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[_shopName setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
_shopName.backgroundColor = [UIColor clearColor];
[_shopName setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
_shopName.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[self.view addSubview:_shopName]; _capPicBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-,,,)];
[_capPicBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[_capPicBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[_capPicBtn setTitle:[NSString stringWithFormat:@"加入对比"] forState: UIControlStateNormal];
_capPicBtn.backgroundColor = [UIColor clearColor];
[_capPicBtn setTitleColor:self.view.tintColor forState:UIControlStateNormal];
_capPicBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[_capPicBtn addTarget:self action:@selector(capPicBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_capPicBtn]; _lineView = [[UIView alloc] initWithFrame:CGRectMake(, , kScreenWidth, 0.9)];
_lineView.backgroundColor = [UIColor colorWithHue: saturation: brightness:0.85 alpha:0.85];
[self.view addSubview:_lineView]; _mWebView = [[UIWebView alloc] initWithFrame:CGRectMake(,,kScreenWidth,kScreenHeight-)];
[self.view addSubview:_mWebView]; UIButton *returnimgbtn = [[UIButton alloc] initWithFrame:CGRectMake(,,,)];
[returnimgbtn setImage:[UIImage imageNamed:@"back_b.png"]forState:UIControlStateNormal];
[returnimgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[returnimgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
returnimgbtn.backgroundColor = [UIColor clearColor];
[returnimgbtn setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
returnimgbtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[returnimgbtn addTarget:self action:@selector(returnApp) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:returnimgbtn]; if([shopname rangeOfString:@"贝贝"].location != NSNotFound || [shopname rangeOfString:@"亚马逊"].location != NSNotFound || [shopname rangeOfString:@"天猫"].location != NSNotFound){
UIButton *backimgbtn = [[UIButton alloc] initWithFrame:CGRectMake(,,,)];
[backimgbtn setImage:[UIImage imageNamed:@"hb_back.png"]forState:UIControlStateNormal];
[backimgbtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[backimgbtn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
backimgbtn.backgroundColor = [UIColor clearColor];
[backimgbtn setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
backimgbtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[backimgbtn addTarget:self action:@selector(backPageBtn) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backimgbtn];
} // back_b.png hb_back.png // NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// NSString *urlStr = [defaults stringForKey:@"urlshopname"];
// if(urlStr){
// self.title =urlStr;
// } // self.mWebView.scalesPageToFit = YES;
self.mWebView.scrollView.showsVerticalScrollIndicator = YES;
self.mWebView.hidden = YES;
self.mWebView.delegate = self;
self.loadedURL = NULL; self.netWorking = [BaseSVRRequestOperator new];
[Utilities addMyGifImageView:self];
[self addWebViewURL]; [self writeClickRecord]; [self performSelector:@selector(timeOut:) withObject:self afterDelay:MAXTIMEOUT];
}
-(void)writeClickRecord
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *goodsid = [NSNumber numberWithInt:[[defaults stringForKey:@"goodsiddata"] intValue]];
NSNumber *itemid = [NSNumber numberWithInt:[[defaults stringForKey:@"itemiddata"] intValue]];
AppDelegate *myDelegate =(AppDelegate*)[[UIApplication sharedApplication] delegate];
NSNumber *uuid = [NSNumber numberWithInt:myDelegate.uuid]; HttpConnect * connect = [[HttpConnect alloc] init];
connect.delegate = self; NSString *UDID=[DBStrore sharedDBStore].sessionId;
NSLog(@"write click :%@-%d-%d-%d",UDID,[uuid intValue],[goodsid intValue],myDelegate.share);
NSMutableDictionary * dic = [NSMutableDictionary dictionary]; [dic setObject:UDID forKey:@"udid"];
[dic setObject:uuid forKey:@"uuid"]; if([[defaults stringForKey:@"itemiddata"] intValue]==-){
NSLog(@"itemid=%d",[itemid intValue]); }
else if([[defaults stringForKey:@"itemiddata"] intValue]!=){
NSLog(@"itemid=%d",[itemid intValue]);
[dic setObject:itemid forKey:@"itemid"];
[connect postRequestForPostValue:dic url:@"addclick.php" requestTag:];
}
else{
NSNumber *adid = [NSNumber numberWithInt:[[defaults stringForKey:@"adiddata"] intValue]];
NSLog(@"adid=%d",[adid intValue]);
[dic setObject:adid forKey:@"adid"];
[connect postRequestForPostValue:dic url:@"addadclick.php" requestTag:];
} } -(void)postRequestStarted:(AFHTTPRequestOperation*)request manage:(AFHTTPRequestOperationManager*)manage{ NSLog(@"REQ START");
}
-(void)postRequestFinished:(AFHTTPRequestOperation*)request manage:(AFHTTPRequestOperationManager*)manage{ NSLog(@"REQ FINISHED"); NSDictionary * dictionary = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableLeaves error:nil ];
NSString * status = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"status"]]; if([status isEqualToString: @""]){ NSLog(@"REQ success");
}
else{
NSLog(@"REQ error status=@%@",status);
} }
-(void)postRequestFailed:(AFHTTPRequestOperation*)request manage:(AFHTTPRequestOperationManager*)manage{ NSLog(@"REQ FAILED"); } - (void)timeOut:(id)time
{
[Utilities removeMyGifImageView:self.view]; if(self.loadedURL == NULL){
UIButton *reloadBtn = [[UIButton alloc] initWithFrame:CGRectMake(/,/,kScreenWidth-,kScreenHeight-)];
[reloadBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[reloadBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[reloadBtn setTitle:[NSString stringWithFormat:@"重试"] forState: UIControlStateNormal];
reloadBtn.backgroundColor = [UIColor clearColor];
[reloadBtn setTitleColor:self.view.tintColor forState:UIControlStateNormal];
reloadBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
[reloadBtn addTarget:self action:@selector(initview) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:reloadBtn];
_mReloadBtn=reloadBtn; }
}
- (void)backPageBtn
{
NSLog(@"backPageBtn");
if([self.mWebView canGoBack])
{
[self.mWebView goBack];
}
else
{
[[DBStrore sharedDBStore] removeInformationView:];
}
}
- (void)addWebViewURL
{
// NSString *urlStr = @"http://www.jd.com";
// NSURL *URL = [NSURL URLWithString:str]; //string>url
// NSString *str1 = [URL absoluteString]; //url>string
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *urlStr = [defaults stringForKey:@"urldata"];
NSString *shopname = [defaults stringForKey:@"shopnamedata"]; [_shopName setTitle:shopname forState: UIControlStateNormal]; NSLog(@"webpage old url:%@",urlStr); //urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF32StringEncoding];
NSLog(@"webpage url:%@",urlStr);
NSURL *url = [NSURL URLWithString:urlStr]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:MAXTIMEOUT];
[self.mWebView loadRequest:request];
NSLog(@"webpage request ok ");
}
- (void)returnApp
{
NSLog(@"returnApp");
[[DBStrore sharedDBStore] removeInformationView:];
} - (void)capPicBtnClick
{
NSLog(@"capPic");
if(self.loadedURL != NULL){ UIGraphicsBeginImageContextWithOptions(CGSizeMake(kCapPicWidth, kCapPicHeight), YES, ); //设置截屏大小
[[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = viewImage.CGImage;
CGRect rect = CGRectMake(kCapPicStartx, kCapPicStarty, kCapPicWidth, kCapPicHeight);//这里可以设置想要截图的区域
CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];
// UIImageWriteToSavedPhotosAlbum(sendImage, nil, nil, nil);//保存图片到照片库
NSData *imageViewData = UIImagePNGRepresentation(sendImage); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:];
NSString *pictureName= [NSString stringWithFormat:@"screenShow_%@.png",[self md5:self.loadedURL]];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:pictureName]; NSLog(@"url: %@", self.loadedURL);
NSString *titlename=[_shopName.titleLabel.text stringByReplacingOccurrencesOfString:@"搜" withString:@""];
titlename=[titlename stringByReplacingOccurrencesOfString:@"同品类" withString:@""];
NSString *key= [NSString stringWithFormat:@"%@,%@,%@",titlename,savedImagePath,self.loadedURL]; NSLog(@"capPicBtnClick count: %d",[DBStrore sharedDBStore].CapPicArray.count); NSFileManager *fileManager=[[NSFileManager alloc] init];
NSError *error; for(int i=;i<[DBStrore sharedDBStore].CapPicArray.count;i++){
if([[DBStrore sharedDBStore].CapPicArray[i] isEqualToString:key]){
NSLog(@"remove at %d",i); if([fileManager fileExistsAtPath:savedImagePath]){
NSLog(@"del imgpath:%@",savedImagePath);
[fileManager removeItemAtPath:savedImagePath error: &error];
if(error){
NSLog(@"del file error = %@",error);
}
}
[imageViewData writeToFile:savedImagePath atomically:YES];//保存照片到沙盒目录
CGImageRelease(imageRefRect);
[self archivedCapPic]; NSLog(@"notify freshCapPicCount");
[[NSNotificationCenter defaultCenter] postNotificationName:@"freshCapPicCount" object:nil userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"capPicChanged" object:nil userInfo:nil];
[Utilities showAlertView:@"加入成功"];
return ;
}
} [imageViewData writeToFile:savedImagePath atomically:YES];//保存照片到沙盒目录
CGImageRelease(imageRefRect); if([DBStrore sharedDBStore].CapPicArray.count == MAXCOUNT)
{
NSFileManager *fileManager=[[NSFileManager alloc] init];
NSError *error; NSString *keytmp = [DBStrore sharedDBStore].CapPicArray[];
NSArray *tmparr=[keytmp componentsSeparatedByString:@","];
NSString *imagePath=tmparr[];
if([fileManager fileExistsAtPath:imagePath]){
NSLog(@"del imgpath:%@",imagePath);
[fileManager removeItemAtPath:imagePath error: &error];
if(error){
NSLog(@"del file error = %@",error);
}
} [[DBStrore sharedDBStore].CapPicArray removeObjectAtIndex:]; }
NSLog(@"3 saveKey count: %d",[DBStrore sharedDBStore].CapPicArray.count);
[[DBStrore sharedDBStore].CapPicArray addObject:key];
NSLog(@"4 saveKey count: %d",[DBStrore sharedDBStore].CapPicArray.count);
[self archivedCapPic]; NSLog(@"notify freshCapPicCount");
[[NSNotificationCenter defaultCenter] postNotificationName:@"freshCapPicCount" object:nil userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"capPicChanged" object:nil userInfo:nil]; [Utilities showAlertView:@"加入成功"];
}
else{
[Utilities showAlertView:@"加载中。。请稍后再试"];
}
}
- (NSString *) md5:(NSString *) input {
const char *cStr = [input UTF8String];
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * ]; for(int i = ; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]]; return output;
}
- (void)archivedCapPic
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *bindUserLocalSettingDictionaryData = [NSKeyedArchiver archivedDataWithRootObject:[DBStrore sharedDBStore].CapPicArray];
[defaults setObject:bindUserLocalSettingDictionaryData forKey:FTcapPic];
[defaults synchronize]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark UIWebViewDelegate - (void )webViewDidFinishLoad:(UIWebView *)webView
{
// [self.mWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"common.checkIos('%@')", @"ios"]];
self.mWebView.hidden = NO;
[Utilities removeMyGifImageView:self.view];
self.loadedURL=[NSString stringWithFormat:@"%@",webView.request.URL.absoluteString];
NSLog(@"webViewDidFinishLoad url:%@",webView.request.URL.absoluteString);
if(_mReloadBtn!=nil){
[_mReloadBtn removeFromSuperview];
_mReloadBtn=nil;
} } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[Utilities removeMyGifImageView:self.view]; } - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{ if(request != nil){
NSURL *url = request.URL; if(url !=nil){
// 要处理的代码
// ...... NSLog(@"url.scheme=%@",url.scheme);
//拦截app跳转
if ([url.scheme isEqualToString:@"weixin"])
{
NSLog(@"return weixin");
return YES;
}
if ([url.scheme isEqualToString:@"alipay"])
{
NSLog(@"return alipay");
return YES;
}
if (!([url.scheme isEqualToString:@"http"]) && !([url.scheme isEqualToString:@"https"]))
{
NSLog(@"return no");
return NO;
}
NSLog(@"return yes"); }
} return YES;
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end 加扣群385378208即可下载工程源码
加扣群385378208即可下载工程源码

iOS开发总结-UIWebView 集成 浏览器的更多相关文章

  1. iOS开发之支付宝集成

    项目中要用到支付功能,需要支付宝,微信,银联三大支付,所以打算总结一下,写两篇文章,方便以后的查阅, 大家在做的时候也能稍微参考下,用到的地方避免再次被坑.这是第二篇支付宝集成,第一篇银联支付在这里. ...

  2. 【iOS开发】UIWebView与JavaScript(JS) 回调交互

    ------------------------------------------------- 很多关于objc 与 js 交互的文章都比较适用于 mac开发,iOS的webview 还是有所不一 ...

  3. ios开发之--UIWebView全属性

    最近的项目当中需要用到html和ios的交互,所以就凑空整理一下,所有webView相关的方法和属性,如有不对的地方,请大家不吝指教! 代码如下: 1,创建webview并设置代理 UIWebView ...

  4. iOS:iOS开发非常全的三方库、插件等等

    iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...

  5. iOS开发--iOS及Mac开源项目和学习资料

    文/零距离仰望星空(简书作者)原文链接:http://www.jianshu.com/p/f6cdbc8192ba著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 原文出处:codecl ...

  6. iOS开发常用第三方库

    UI 动画 网络相关 Model 其他 数据库 缓存处理 PDF 图像浏览及处理 摄像照相视频音频处理 响应式框架 消息相关 版本新API的Demo 代码安全与密码 测试及调试 AppleWatch ...

  7. iOS开发之资料收集

    github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自github:https://github ...

  8. iOS开发 非常全的三方库、插件、大牛博客等等

    UI 下拉刷新 EGOTableViewPullRefresh- 最早的下拉刷新控件. SVPullToRefresh- 下拉刷新控件. MJRefresh- 仅需一行代码就可以为UITableVie ...

  9. iOS开发---集成百度地图完善版

    一.成为百度的开发者.创建应用 http://developer.baidu.com/map/index.php?title=首页 (鼠标移向 然后选择你的项目需要的功能 你可以在里面了解到你想要使用 ...

随机推荐

  1. 读书笔记之 - javascript 设计模式 - 享元模式

    本章探讨另一种优化模式-享元模式,它最适合于解决因创建大量类似对象而累及性能的问题.这种模式在javascript中尤其有用,因为复杂的javascript代码很快就会用光浏览器的所有可用内存,通过把 ...

  2. C++ 类访问控制(public/protected/private)

    第一:private, public, protected 访问标号的访问范围. private:只能由1.该类中的函数.2.其友元函数访问. 不能被任何其他访问,该类的对象也不能访问. protec ...

  3. [Machine Learning] 梯度下降(BGD)、随机梯度下降(SGD)、Mini-batch Gradient Descent、带Mini-batch的SGD

    一.回归函数及目标函数 以均方误差作为目标函数(损失函数),目的是使其值最小化,用于优化上式. 二.优化方式(Gradient Descent) 1.最速梯度下降法 也叫批量梯度下降法Batch Gr ...

  4. Spring MVC 3.2 406 Not Acceptable

    Spring MVC 3.2 406 Not Acceptable 这个报错主要是因为SpringMVC配置文件配置问题. 修改步骤如下: 首先,修改spring-mvc.xsd为 spring-mv ...

  5. winfrom中按钮文本&的显示问题/按钮快捷键设置问题

    其实这个问题是因为“&”有特殊的意义-就是可以作为快捷键 第一种:Alt + *(按钮快捷键) 在大家给button.label.menuStrip等控件设置Text属性时在名字后边加& ...

  6. HTML 5结构

    进行总体布局时候,具体可以用的方法. 1.大纲:文档中各内容区块的结构编排. 内容区块可以使用标题元素来展示各级内容区块的标题. 关于内容区块的编排可以分为“显示编排”和“隐式编排”. 显示编排:明确 ...

  7. 学渣也要搞 laravel(1)—— 安装篇

    看到laravel(我叫它:拉瓦)那么热门,我也决定学上一学. Laravel 5.2 在 5.1 基础上继续改进和优化,添加了许多新的功能特性:多认证驱动支持.隐式模型绑定.简化Eloquent 全 ...

  8. LVS原理详解及部署之二:LVS原理详解(3种工作方式8种调度算法)

    一.集群简介 什么是集群 计算机集群简称集群是一种计算机系统,它通过一组松散集成的计算机软件和/或硬件连接起来高度紧密地协作完成计算工作.在某种意义上,他们可以被看作是一 台计算机.集群系统中的单个计 ...

  9. Python 学习之urllib模块---用于发送网络请求,获取数据

    1.urllib urllib是Python标准库的一部分,包含urllib.request,urllib.error,urllib.parse,urlli.robotparser四个子模块. (1) ...

  10. SNN--Second Name Node

    NameNode有这么几个配置: Property Description Suggested value dfs.name.dir Directory in NameNode’s local fil ...