活动模块UIWebView
来源:互联网 发布:大数据对零售业的影响 编辑:程序博客网 时间:2024/05/30 07:12
今天还有接下来的几天要跟webView打交道了:
下边是我找的一些跟WebvView相关的资料:
http://www.jianshu.com/p/3d7e4804033b
http://bxbxbai.gitcafe.io/2015/08/16/talk-about-bybird-app/
http://www.jianshu.com/p/ca496cb680fe
首先,让我们了解一下UIWebView。
加载本地html页面:
NSString *webPath = [[NSBundle mainBundle]pathForResource:@“HelloWord"ofType:@"html”];//获取文件路径NSURL *webURL = [NSURL fileURLWithPath:webPath];//通过文件路径字符串设置URLNSURLRequest *URLRequest = [NSURL RequestrequestWithURL:webURL];//设置请求提交的相关URL[self.webViewloadRequest:URLRequest];//提交请求
1、请求网络获取html
我们的项目需要带参数的网络请求,返回一个html页面
//********************** AF begin ************************* //增加这几行代码; AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init]; [securityPolicy setAllowInvalidCertificates:YES]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; //这里进行设置; [manager setSecurityPolicy:securityPolicy]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager POST:ACTIVITYLIST parameters:params success:^(AFHTTPRequestOperation *operation,id responseObject){ NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"成功: %@", string); } failure:^(AFHTTPRequestOperation *operation,NSError *error){ NSLog(@"失败: %@", error); }]; //********************** AF over ********************
2、拿到str之后展示在webView上
[self.activityWebView loadHTMLString:string baseURL:nil];
3、拦截URL处理
在代理方法-(BOOL)webView:(UIWebView
)webView shouldStartLoadWithRequest:(NSURLRequest )request navigationType:(UIWebViewNavigationType)navigationType中拦截处理跳转URL
4、js调用Object-c函数
//js交互 JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];//未登录或者token失效,请求登录,toLoginByAPP是约定好的函数名称 context[@"toLoginByAPP"] = ^() { NSLog(@"+++++++Begin toLoginByAPP+++++++"); NSArray *args = [JSContext currentArguments]; for (JSValue *jsVal in args) { NSLog(@"toLoginByAPP:%@", jsVal); } JSValue *this = [JSContext currentThis]; NSLog(@"toLoginByAPP——this: %@",this); NSLog(@"-------End toLoginByAPP-------"); };
0 0
- 活动模块UIWebView
- inspect模块---检查活动对象
- UIWebView中添加活动指示器,来化解用户等待心理
- 模块——UIWebview的应用
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebview
- UIWebView
- UIWebView
- 关系型数据库&&非关系型数据库
- 二叉树的深度
- JetBrains发布DataGrip 1.0——数据库与SQL领域中的瑞士军刀
- 再学习---Android相对布局(RelativeLayout)
- 唯爱小粽子:Mac下Nginx启动、重启和关闭
- 活动模块UIWebView
- JSONArray的应用
- awakeFromNib
- Android getReadableDatabase() 和 getWritableDatabase()
- iOS 利用UISCrollView作广告自动轮播效果
- cordova创建iOS项目
- 设计模式之中介者模式
- PHP获取某年第几周的开始日期和结束日期
- 李白打酒(DFS搜索)