//
//  FRXPayWebViewController.m
//  FRXPayDemo
//
//  Created by weiwei on 15/11/17.
//  Copyright © 2015年 chenwei. All rights reserved.
//

#import "XFBPayWebViewController.h"

@interface XFBPayWebViewController () <UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation XFBPayWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    self.webView.delegate = self;
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    
    self.webView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    // Do any additional setup after loading the view.
}


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *url = [NSString stringWithFormat:@"%@",request.URL];
    NSLog(@"url--%@",url);
    if ([url hasSuffix:@"#colseme"]) {
        [self colse];
        return NO;
    }
    
    //
//    if ([url hasPrefix:@"http://www.xiangfubao.com.cn/"]) {
//        [self colse];
//        return YES;
//    }
    
    return YES;
}

- (void)colse
{
    [self.navigationController popViewControllerAnimated:YES];
}

//可以添加loading
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"loding...");
    NSLog(@"%s",__FUNCTION__);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    self.title = title;
    NSLog(@"finish...");
    NSLog(@"%s",__FUNCTION__);
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error
{
    NSLog(@"finish...");
    NSLog(@"%s",__FUNCTION__);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#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
