1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// UIViewController+HTTP.m
// iCemarose
//
// Created by Sanchew on 2017/7/13.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "UIViewController+HTTP.h"
#import <JLRoutes/JLRoutes.h>
#import <RegexKitLite/RegexKitLite.h>
#import <TOWebViewController/TOWebViewController.h>
#import "AppDelegate.h"
@implementation UIViewController (HTTP)
- (void)openURLWithString:(NSString *)URLString {
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]];
}
NSURL *url = [[NSURL alloc] initWithString:[encodeURL stringByReplacingOccurrencesOfRegex:@"^https?" withString:@"cemarose"]];
if ([JLRoutes canRouteURL:url]) {
[JLRoutes routeURL:url];
// }else if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
// [application openURL:[NSURL URLWithString:URLString] options:@{} completionHandler:nil];
} else {
// [application openURL:[NSURL URLWithString:URLString]];
TOWebViewController *wv = [[TOWebViewController alloc] initWithURLString:URLString];
[[AppDelegate mainViewController].selectedViewController pushViewController:wv animated:YES];
}
}
@end