UIViewController+HTTP.m 1.84 KB
Newer Older
lee committed
1 2 3 4 5 6 7 8 9
//
//  UIViewController+HTTP.m
//  iCemarose
//
//  Created by Sanchew on 2017/7/13.
//  Copyright © 2017年 kollway. All rights reserved.
//

#import "UIViewController+HTTP.h"
lee committed
10 11
#import <JLRoutes/JLRoutes.h> 
#import <RegexKitLite/RegexKitLite.h>
12 13
//#import <TOWebViewController/TOWebViewController.h>
#import "DPWebViewController.h"
lee committed
14
#import "AppDelegate.h"
15
#import "KWMWebViewVC.h"
lee committed
16 17 18 19

@implementation UIViewController (HTTP)

- (void)openURLWithString:(NSString *)URLString {
u  
lee committed
20 21 22 23 24 25 26 27
    NSString *parten=@"[^%\\da-zA-Z:/.?&=]+";
    NSRegularExpression *reg=[NSRegularExpression regularExpressionWithPattern:parten options:0 error:nil];
    NSArray *matchs=[reg matchesInString:URLString options:0 range:NSMakeRange(0, [URLString length])];
    NSString *encodeURL=[NSString stringWithString:URLString];
    for (long i=matchs.count-1; i>=0; --i) {
        NSTextCheckingResult *tcr=matchs[i];
        encodeURL=[encodeURL stringByReplacingCharactersInRange:tcr.range withString:[[encodeURL substringWithRange:tcr.range] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    }
28
//    NSURL *url = [[NSURL alloc] initWithString:[encodeURL stringByReplacingOccurrencesOfRegex:@"^https?" withString:@"cemarose"]];
u  
lee committed
29
    NSURL *url = [[NSURL alloc] initWithString:encodeURL];
lee committed
30 31
    if ([JLRoutes canRouteURL:url]) {
        [JLRoutes routeURL:url];
lee committed
32 33
//    }else if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
//        [application openURL:[NSURL URLWithString:URLString] options:@{} completionHandler:nil];
u  
lee committed
34
    } else if(url){
lee committed
35
//        [application openURL:[NSURL URLWithString:URLString]];
u  
lee committed
36
        TOWebViewController *wv = [[DPWebViewController alloc] initWithURLString:encodeURL];
37
        wv.hidesBottomBarWhenPushed = YES;
lee committed
38
        [[AppDelegate mainViewController].selectedViewController pushViewController:wv animated:YES];
lee committed
39
    }
lee committed
40 41 42
}

@end