├── .DS_Store ├── Readme.md ├── ZLCWebView Resource ├── ZLCWebView.h └── ZLCWebView.m ├── ZLCWebView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── shining3d.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── zhailiuchuang.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── shining3d.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── ZLCWebView.xcscheme │ │ └── xcschememanagement.plist │ └── zhailiuchuang.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── ZLCWebView.xcscheme │ └── xcschememanagement.plist └── ZLCWebView ├── .DS_Store ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── ZLCWebView Resource ├── ZLCWebView.h └── ZLCWebView.m ├── ZLCWebView.xcdatamodeld ├── .xccurrentversion └── ZLCWebView.xcdatamodel │ └── contents └── main.m /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lczhai/ZLCWebView/79efc7825073067317573c04ae246b8600631a2b/.DS_Store -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | # ZLCWebView github: https://github.com/lczhai/ZLCWebView 3 | ----- 4 | 5 | ### 将UIWebVIew和WKWebView封装到一起,当系统版本大于8.0时候选择WKWebView降低性能消耗,当小于8.0时候使用UIWebView进行加载 6 | 7 | 8 | ____ ios 8.0以上使用ZLCWebView 加载“http://www.baidu.com” ____ 9 | 10 | ![zlcwebview.png](http://upload-images.jianshu.io/upload_images/2312430-a6ea4a847b0e879d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 11 | 12 | 13 | ____ ios 8.0以上使用UIWebView 加载“http://www.baidu.com” ____ 14 | 15 | ![uiwebview.png](http://upload-images.jianshu.io/upload_images/2312430-b509ba25268d018b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 16 | 17 | 18 | 19 | 20 | 21 | ##### 1、将项目中的根目录中的“ZLCWebView源文件”中的ZLCWebView.h及m拖入工程(或直接在项目中拖出) 22 | 23 | ##### 2、在项目Targets ->build Phases ->link Binary With Libraries 中添加WebKit.framework(否则Deployment Target调整成7.0时,运行程序就会报错) 24 | 25 | ##### 3、在自己的目标视图加载即可 26 | 27 | 28 | ```objectivec 29 | //在目标视图内初始化ZLCWebView 30 | ZLCWebView *my = [[ZLCWebView alloc]initWithFrame:self.view.bounds]; 31 | [my loadURLString:@"http://www.baidu.com"]; 32 | my.delegate = self; 33 | [self.view addSubview:my]; 34 | ``` 35 | 36 | //让视图遵守ZLCWebView的delegate并实现ZLCWebView的delegate 37 | 38 | ```objectivec 39 | - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview 40 | { 41 | NSLog(@"页面开始加载"); 42 | } 43 | 44 | - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL 45 | { 46 | NSLog(@"截取到URL:%@",URL); 47 | } 48 | - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL 49 | { 50 | NSLog(@"页面加载完成"); 51 | 52 | } 53 | 54 | - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error 55 | { 56 | NSLog(@"加载出现错误"); 57 | } 58 | 59 | ``` 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /ZLCWebView Resource/ZLCWebView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZLCWebView.h 3 | // 测试 4 | // 5 | // Created by shining3d on 16/6/17. 6 | // Copyright © 2016年 shining3d. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class ZLCWebView; 13 | @protocol ZLCWebViewDelegate 14 | @optional 15 | - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL; 16 | - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error; 17 | - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL; 18 | - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview; 19 | @end 20 | 21 | @interface ZLCWebView : UIView 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | #pragma mark - Public Properties 32 | 33 | //zlcdelegate 34 | @property (nonatomic, weak) id delegate; 35 | 36 | // The main and only UIProgressView 37 | @property (nonatomic, strong) UIProgressView *progressView; 38 | // The web views 39 | // Depending on the version of iOS, one of these will be set 40 | @property (nonatomic, strong) WKWebView *wkWebView; 41 | @property (nonatomic, strong) UIWebView *uiWebView; 42 | 43 | 44 | 45 | #pragma mark - Initializers view 46 | - (instancetype)initWithFrame:(CGRect)frame; 47 | 48 | 49 | #pragma mark - Static Initializers 50 | @property (nonatomic, strong) UIBarButtonItem *actionButton; 51 | @property (nonatomic, strong) UIColor *tintColor; 52 | @property (nonatomic, strong) UIColor *barTintColor; 53 | @property (nonatomic, assign) BOOL actionButtonHidden; 54 | @property (nonatomic, assign) BOOL showsURLInNavigationBar; 55 | @property (nonatomic, assign) BOOL showsPageTitleInNavigationBar; 56 | 57 | //Allow for custom activities in the browser by populating this optional array 58 | @property (nonatomic, strong) NSArray *customActivityItems; 59 | 60 | #pragma mark - Public Interface 61 | 62 | 63 | // Load a NSURLURLRequest to web view 64 | // Can be called any time after initialization 65 | - (void)loadRequest:(NSURLRequest *)request; 66 | 67 | // Load a NSURL to web view 68 | // Can be called any time after initialization 69 | - (void)loadURL:(NSURL *)URL; 70 | 71 | // Loads a URL as NSString to web view 72 | // Can be called any time after initialization 73 | - (void)loadURLString:(NSString *)URLString; 74 | 75 | 76 | // Loads an string containing HTML to web view 77 | // Can be called any time after initialization 78 | - (void)loadHTMLString:(NSString *)HTMLString; 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /ZLCWebView Resource/ZLCWebView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZLCWebView.m 3 | // 测试 4 | // 5 | // Created by shining3d on 16/6/17. 6 | // Copyright © 2016年 shining3d. All rights reserved. 7 | // 8 | 9 | #import "ZLCWebView.h" 10 | 11 | #define isiOS8 [[[UIDevice currentDevice] systemVersion] floatValue]>=8.0 12 | static void *KINWebBrowserContext = &KINWebBrowserContext; 13 | 14 | 15 | @interface ZLCWebView () 16 | @property (nonatomic, strong) NSTimer *fakeProgressTimer; 17 | @property (nonatomic, assign) BOOL uiWebViewIsLoading; 18 | @property (nonatomic, strong) NSURL *uiWebViewCurrentURL; 19 | @property (nonatomic, strong) NSURL *URLToLaunchWithPermission; 20 | @property (nonatomic, strong) UIAlertView *externalAppPermissionAlertView; 21 | 22 | 23 | @end 24 | 25 | 26 | 27 | @implementation ZLCWebView 28 | 29 | 30 | 31 | 32 | #pragma mark --Initializers 33 | - (instancetype)initWithFrame:(CGRect)frame 34 | { 35 | self = [super initWithFrame:frame]; 36 | if (self) { 37 | 38 | 39 | if(isiOS8) { 40 | 41 | self.wkWebView = [[WKWebView alloc] init]; 42 | 43 | } 44 | else { 45 | self.uiWebView = [[UIWebView alloc] init]; 46 | } 47 | 48 | 49 | self.backgroundColor = [UIColor redColor]; 50 | 51 | if(self.wkWebView) { 52 | [self.wkWebView setFrame:frame]; 53 | [self.wkWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 54 | [self.wkWebView setNavigationDelegate:self]; 55 | [self.wkWebView setUIDelegate:self]; 56 | [self.wkWebView setMultipleTouchEnabled:YES]; 57 | [self.wkWebView setAutoresizesSubviews:YES]; 58 | [self.wkWebView.scrollView setAlwaysBounceVertical:YES]; 59 | [self addSubview:self.wkWebView]; 60 | self.wkWebView.scrollView.bounces = NO; 61 | [self.wkWebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:KINWebBrowserContext]; 62 | } 63 | else { 64 | [self.uiWebView setFrame:frame]; 65 | [self.uiWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 66 | [self.uiWebView setDelegate:self]; 67 | [self.uiWebView setMultipleTouchEnabled:YES]; 68 | [self.uiWebView setAutoresizesSubviews:YES]; 69 | [self.uiWebView setScalesPageToFit:YES]; 70 | [self.uiWebView.scrollView setAlwaysBounceVertical:YES]; 71 | self.uiWebView.scrollView.bounces = NO; 72 | [self addSubview:self.uiWebView]; 73 | } 74 | 75 | 76 | 77 | 78 | 79 | self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; 80 | [self.progressView setTrackTintColor:[UIColor colorWithWhite:1.0f alpha:0.0f]]; 81 | [self.progressView setFrame:CGRectMake(0, 64, self.frame.size.width, self.progressView.frame.size.height)]; 82 | 83 | //设置进度条颜色 84 | [self setTintColor:[UIColor colorWithRed:0.400 green:0.863 blue:0.133 alpha:1.000]]; 85 | [self addSubview:self.progressView]; 86 | 87 | 88 | } 89 | return self; 90 | } 91 | 92 | 93 | 94 | #pragma mark - Public Interface 95 | - (void)loadRequest:(NSURLRequest *)request { 96 | if(self.wkWebView) { 97 | [self.wkWebView loadRequest:request]; 98 | } 99 | else { 100 | [self.uiWebView loadRequest:request]; 101 | 102 | 103 | } 104 | } 105 | 106 | - (void)loadURL:(NSURL *)URL { 107 | [self loadRequest:[NSURLRequest requestWithURL:URL]]; 108 | } 109 | 110 | - (void)loadURLString:(NSString *)URLString { 111 | NSURL *URL = [NSURL URLWithString:URLString]; 112 | [self loadURL:URL]; 113 | } 114 | 115 | - (void)loadHTMLString:(NSString *)HTMLString { 116 | if(self.wkWebView) { 117 | [self.wkWebView loadHTMLString:HTMLString baseURL:nil]; 118 | } 119 | else if(self.uiWebView) { 120 | [self.uiWebView loadHTMLString:HTMLString baseURL:nil]; 121 | } 122 | } 123 | 124 | 125 | 126 | - (void)setTintColor:(UIColor *)tintColor { 127 | _tintColor = tintColor; 128 | [self.progressView setTintColor:tintColor]; 129 | } 130 | 131 | - (void)setBarTintColor:(UIColor *)barTintColor { 132 | _barTintColor = barTintColor; 133 | } 134 | 135 | 136 | 137 | #pragma mark - UIWebViewDelegate 138 | 139 | - (void)webViewDidStartLoad:(UIWebView *)webView 140 | { 141 | if(webView == self.uiWebView) { 142 | [self.delegate zlcwebViewDidStartLoad:self]; 143 | 144 | } 145 | } 146 | 147 | //监视请求 148 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 149 | 150 | 151 | 152 | 153 | 154 | if(webView == self.uiWebView) { 155 | 156 | if(![self externalAppRequiredToOpenURL:request.URL]) { 157 | self.uiWebViewCurrentURL = request.URL; 158 | self.uiWebViewIsLoading = YES; 159 | 160 | [self fakeProgressViewStartLoading]; 161 | 162 | 163 | //back delegate 164 | [self.delegate zlcwebView:self shouldStartLoadWithURL:request.URL]; 165 | return YES; 166 | } 167 | else { 168 | [self launchExternalAppWithURL:request.URL]; 169 | return NO; 170 | } 171 | } 172 | return NO; 173 | } 174 | 175 | 176 | - (void)webViewDidFinishLoad:(UIWebView *)webView { 177 | 178 | 179 | NSLog(@"alert : currwebview is UIWebView"); 180 | if(webView == self.uiWebView) { 181 | if(!self.uiWebView.isLoading) { 182 | self.uiWebViewIsLoading = NO; 183 | 184 | [self fakeProgressBarStopLoading]; 185 | } 186 | 187 | //back delegate 188 | [self.delegate zlcwebView:self didFinishLoadingURL:self.uiWebView.request.URL]; 189 | 190 | } 191 | } 192 | 193 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 194 | 195 | if(webView == self.uiWebView) { 196 | if(!self.uiWebView.isLoading) { 197 | self.uiWebViewIsLoading = NO; 198 | 199 | [self fakeProgressBarStopLoading]; 200 | } 201 | 202 | //back delegate 203 | [self.delegate zlcwebView:self didFailToLoadURL:self.uiWebView.request.URL error:error]; 204 | } 205 | } 206 | 207 | 208 | #pragma mark - WKNavigationDelegate 209 | 210 | 211 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { 212 | if(webView == self.wkWebView) { 213 | 214 | 215 | 216 | 217 | //back delegate 218 | [self.delegate zlcwebViewDidStartLoad:self]; 219 | 220 | 221 | // WKNavigationActionPolicy(WKNavigationActionPolicyAllow); 222 | 223 | } 224 | } 225 | 226 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { 227 | NSLog(@"alert : currwebview is WKWebView"); 228 | 229 | if(webView == self.wkWebView) { 230 | 231 | //back delegate 232 | [self.delegate zlcwebView:self didFinishLoadingURL:self.wkWebView.URL]; 233 | } 234 | } 235 | 236 | - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation 237 | withError:(NSError *)error { 238 | if(webView == self.wkWebView) { 239 | //back delegate 240 | [self.delegate zlcwebView:self didFailToLoadURL:self.wkWebView.URL error:error]; 241 | } 242 | 243 | } 244 | 245 | - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation 246 | withError:(NSError *)error { 247 | if(webView == self.wkWebView) { 248 | //back delegate 249 | [self.delegate zlcwebView:self didFailToLoadURL:self.wkWebView.URL error:error]; 250 | } 251 | } 252 | 253 | - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { 254 | 255 | 256 | if(webView == self.wkWebView) { 257 | 258 | NSURL *URL = navigationAction.request.URL; 259 | if(![self externalAppRequiredToOpenURL:URL]) { 260 | if(!navigationAction.targetFrame) { 261 | [self loadURL:URL]; 262 | decisionHandler(WKNavigationActionPolicyCancel); 263 | return; 264 | } 265 | [self callback_webViewShouldStartLoadWithRequest:navigationAction.request navigationType:navigationAction.navigationType]; 266 | 267 | } 268 | else if([[UIApplication sharedApplication] canOpenURL:URL]) { 269 | [self launchExternalAppWithURL:URL]; 270 | decisionHandler(WKNavigationActionPolicyCancel); 271 | return; 272 | } 273 | } 274 | 275 | 276 | 277 | decisionHandler(WKNavigationActionPolicyAllow); 278 | 279 | 280 | } 281 | 282 | -(BOOL)callback_webViewShouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(NSInteger)navigationType 283 | { 284 | //back delegate 285 | [self.delegate zlcwebView:self shouldStartLoadWithURL:request.URL]; 286 | return YES; 287 | } 288 | 289 | 290 | #pragma mark - WKUIDelegate 291 | 292 | - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{ 293 | if (!navigationAction.targetFrame.isMainFrame) { 294 | [webView loadRequest:navigationAction.request]; 295 | } 296 | return nil; 297 | } 298 | #pragma mark - Estimated Progress KVO (WKWebView) 299 | 300 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 301 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.wkWebView) { 302 | [self.progressView setAlpha:1.0f]; 303 | BOOL animated = self.wkWebView.estimatedProgress > self.progressView.progress; 304 | [self.progressView setProgress:self.wkWebView.estimatedProgress animated:animated]; 305 | 306 | // Once complete, fade out UIProgressView 307 | if(self.wkWebView.estimatedProgress >= 1.0f) { 308 | [UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{ 309 | [self.progressView setAlpha:0.0f]; 310 | } completion:^(BOOL finished) { 311 | [self.progressView setProgress:0.0f animated:NO]; 312 | }]; 313 | } 314 | } 315 | else { 316 | [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; 317 | } 318 | } 319 | 320 | #pragma mark - Fake Progress Bar Control (UIWebView) 321 | 322 | - (void)fakeProgressViewStartLoading { 323 | [self.progressView setProgress:0.0f animated:NO]; 324 | [self.progressView setAlpha:1.0f]; 325 | 326 | if(!self.fakeProgressTimer) { 327 | self.fakeProgressTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(fakeProgressTimerDidFire:) userInfo:nil repeats:YES]; 328 | } 329 | } 330 | 331 | - (void)fakeProgressBarStopLoading { 332 | if(self.fakeProgressTimer) { 333 | [self.fakeProgressTimer invalidate]; 334 | } 335 | 336 | if(self.progressView) { 337 | [self.progressView setProgress:1.0f animated:YES]; 338 | [UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{ 339 | [self.progressView setAlpha:0.0f]; 340 | } completion:^(BOOL finished) { 341 | [self.progressView setProgress:0.0f animated:NO]; 342 | }]; 343 | } 344 | } 345 | 346 | - (void)fakeProgressTimerDidFire:(id)sender { 347 | CGFloat increment = 0.005/(self.progressView.progress + 0.2); 348 | if([self.uiWebView isLoading]) { 349 | CGFloat progress = (self.progressView.progress < 0.75f) ? self.progressView.progress + increment : self.progressView.progress + 0.0005; 350 | if(self.progressView.progress < 0.95) { 351 | [self.progressView setProgress:progress animated:YES]; 352 | } 353 | } 354 | } 355 | 356 | #pragma mark - External App Support 357 | 358 | - (BOOL)externalAppRequiredToOpenURL:(NSURL *)URL { 359 | 360 | //若需要限制只允许某些前缀的scheme通过请求,则取消下述注释,并在数组内添加自己需要放行的前缀 361 | // NSSet *validSchemes = [NSSet setWithArray:@[@"http", @"https",@"file"]]; 362 | // return ![validSchemes containsObject:URL.scheme]; 363 | 364 | return !URL; 365 | } 366 | 367 | - (void)launchExternalAppWithURL:(NSURL *)URL { 368 | self.URLToLaunchWithPermission = URL; 369 | if (![self.externalAppPermissionAlertView isVisible]) { 370 | [self.externalAppPermissionAlertView show]; 371 | } 372 | 373 | } 374 | 375 | #pragma mark - UIAlertViewDelegate 376 | 377 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 378 | if(alertView == self.externalAppPermissionAlertView) { 379 | if(buttonIndex != alertView.cancelButtonIndex) { 380 | [[UIApplication sharedApplication] openURL:self.URLToLaunchWithPermission]; 381 | } 382 | self.URLToLaunchWithPermission = nil; 383 | } 384 | } 385 | 386 | #pragma mark - Dealloc 387 | 388 | - (void)dealloc { 389 | [self.uiWebView setDelegate:nil]; 390 | [self.wkWebView setNavigationDelegate:nil]; 391 | [self.wkWebView setUIDelegate:nil]; 392 | [self.wkWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))]; 393 | 394 | } 395 | 396 | @end 397 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2B5999671D195DB100A916DB /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2B5999661D195DB100A916DB /* WebKit.framework */; }; 11 | 2B9AD6A01D14DD6D00A81DB5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9AD69F1D14DD6D00A81DB5 /* main.m */; }; 12 | 2B9AD6A31D14DD6D00A81DB5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9AD6A21D14DD6D00A81DB5 /* AppDelegate.m */; }; 13 | 2B9AD6A61D14DD6D00A81DB5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9AD6A51D14DD6D00A81DB5 /* ViewController.m */; }; 14 | 2B9AD6A91D14DD6D00A81DB5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B9AD6A71D14DD6D00A81DB5 /* Main.storyboard */; }; 15 | 2B9AD6AC1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 2B9AD6AA1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodeld */; }; 16 | 2B9AD6AE1D14DD6D00A81DB5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2B9AD6AD1D14DD6D00A81DB5 /* Assets.xcassets */; }; 17 | 2B9AD6B11D14DD6D00A81DB5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B9AD6AF1D14DD6D00A81DB5 /* LaunchScreen.storyboard */; }; 18 | A48B9E431D1CDF82004F137E /* ZLCWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = A48B9E421D1CDF82004F137E /* ZLCWebView.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 2B5999661D195DB100A916DB /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 23 | 2B9AD69B1D14DD6C00A81DB5 /* ZLCWebView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZLCWebView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 2B9AD69F1D14DD6D00A81DB5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 2B9AD6A11D14DD6D00A81DB5 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 26 | 2B9AD6A21D14DD6D00A81DB5 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 27 | 2B9AD6A41D14DD6D00A81DB5 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 28 | 2B9AD6A51D14DD6D00A81DB5 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 29 | 2B9AD6A81D14DD6D00A81DB5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 2B9AD6AB1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = ZLCWebView.xcdatamodel; sourceTree = ""; }; 31 | 2B9AD6AD1D14DD6D00A81DB5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | 2B9AD6B01D14DD6D00A81DB5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 33 | 2B9AD6B21D14DD6D00A81DB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | A48B9E411D1CDF82004F137E /* ZLCWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZLCWebView.h; sourceTree = ""; }; 35 | A48B9E421D1CDF82004F137E /* ZLCWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZLCWebView.m; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 2B9AD6981D14DD6C00A81DB5 /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | 2B5999671D195DB100A916DB /* WebKit.framework in Frameworks */, 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 2B9AD6921D14DD6C00A81DB5 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 2B9AD69D1D14DD6D00A81DB5 /* ZLCWebView */, 54 | 2B9AD69C1D14DD6C00A81DB5 /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 2B9AD69C1D14DD6C00A81DB5 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 2B9AD69B1D14DD6C00A81DB5 /* ZLCWebView.app */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 2B9AD69D1D14DD6D00A81DB5 /* ZLCWebView */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | A48B9E401D1CDF82004F137E /* ZLCWebView Resource */, 70 | 2B9AD6A11D14DD6D00A81DB5 /* AppDelegate.h */, 71 | 2B9AD6A21D14DD6D00A81DB5 /* AppDelegate.m */, 72 | 2B9AD6A41D14DD6D00A81DB5 /* ViewController.h */, 73 | 2B9AD6A51D14DD6D00A81DB5 /* ViewController.m */, 74 | 2B9AD6A71D14DD6D00A81DB5 /* Main.storyboard */, 75 | 2B9AD6AD1D14DD6D00A81DB5 /* Assets.xcassets */, 76 | 2B9AD6AF1D14DD6D00A81DB5 /* LaunchScreen.storyboard */, 77 | 2B9AD6B21D14DD6D00A81DB5 /* Info.plist */, 78 | 2B9AD6AA1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodeld */, 79 | 2B9AD69E1D14DD6D00A81DB5 /* Supporting Files */, 80 | ); 81 | path = ZLCWebView; 82 | sourceTree = ""; 83 | }; 84 | 2B9AD69E1D14DD6D00A81DB5 /* Supporting Files */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 2B5999661D195DB100A916DB /* WebKit.framework */, 88 | 2B9AD69F1D14DD6D00A81DB5 /* main.m */, 89 | ); 90 | name = "Supporting Files"; 91 | sourceTree = ""; 92 | }; 93 | A48B9E401D1CDF82004F137E /* ZLCWebView Resource */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | A48B9E411D1CDF82004F137E /* ZLCWebView.h */, 97 | A48B9E421D1CDF82004F137E /* ZLCWebView.m */, 98 | ); 99 | path = "ZLCWebView Resource"; 100 | sourceTree = ""; 101 | }; 102 | /* End PBXGroup section */ 103 | 104 | /* Begin PBXNativeTarget section */ 105 | 2B9AD69A1D14DD6C00A81DB5 /* ZLCWebView */ = { 106 | isa = PBXNativeTarget; 107 | buildConfigurationList = 2B9AD6B51D14DD6D00A81DB5 /* Build configuration list for PBXNativeTarget "ZLCWebView" */; 108 | buildPhases = ( 109 | 2B9AD6971D14DD6C00A81DB5 /* Sources */, 110 | 2B9AD6981D14DD6C00A81DB5 /* Frameworks */, 111 | 2B9AD6991D14DD6C00A81DB5 /* Resources */, 112 | ); 113 | buildRules = ( 114 | ); 115 | dependencies = ( 116 | ); 117 | name = ZLCWebView; 118 | productName = ZLCWebView; 119 | productReference = 2B9AD69B1D14DD6C00A81DB5 /* ZLCWebView.app */; 120 | productType = "com.apple.product-type.application"; 121 | }; 122 | /* End PBXNativeTarget section */ 123 | 124 | /* Begin PBXProject section */ 125 | 2B9AD6931D14DD6C00A81DB5 /* Project object */ = { 126 | isa = PBXProject; 127 | attributes = { 128 | LastUpgradeCheck = 0720; 129 | ORGANIZATIONNAME = "翟留闯"; 130 | TargetAttributes = { 131 | 2B9AD69A1D14DD6C00A81DB5 = { 132 | CreatedOnToolsVersion = 7.2.1; 133 | }; 134 | }; 135 | }; 136 | buildConfigurationList = 2B9AD6961D14DD6C00A81DB5 /* Build configuration list for PBXProject "ZLCWebView" */; 137 | compatibilityVersion = "Xcode 3.2"; 138 | developmentRegion = English; 139 | hasScannedForEncodings = 0; 140 | knownRegions = ( 141 | en, 142 | Base, 143 | ); 144 | mainGroup = 2B9AD6921D14DD6C00A81DB5; 145 | productRefGroup = 2B9AD69C1D14DD6C00A81DB5 /* Products */; 146 | projectDirPath = ""; 147 | projectRoot = ""; 148 | targets = ( 149 | 2B9AD69A1D14DD6C00A81DB5 /* ZLCWebView */, 150 | ); 151 | }; 152 | /* End PBXProject section */ 153 | 154 | /* Begin PBXResourcesBuildPhase section */ 155 | 2B9AD6991D14DD6C00A81DB5 /* Resources */ = { 156 | isa = PBXResourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 2B9AD6B11D14DD6D00A81DB5 /* LaunchScreen.storyboard in Resources */, 160 | 2B9AD6AE1D14DD6D00A81DB5 /* Assets.xcassets in Resources */, 161 | 2B9AD6A91D14DD6D00A81DB5 /* Main.storyboard in Resources */, 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXResourcesBuildPhase section */ 166 | 167 | /* Begin PBXSourcesBuildPhase section */ 168 | 2B9AD6971D14DD6C00A81DB5 /* Sources */ = { 169 | isa = PBXSourcesBuildPhase; 170 | buildActionMask = 2147483647; 171 | files = ( 172 | 2B9AD6A61D14DD6D00A81DB5 /* ViewController.m in Sources */, 173 | 2B9AD6AC1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodeld in Sources */, 174 | 2B9AD6A31D14DD6D00A81DB5 /* AppDelegate.m in Sources */, 175 | A48B9E431D1CDF82004F137E /* ZLCWebView.m in Sources */, 176 | 2B9AD6A01D14DD6D00A81DB5 /* main.m in Sources */, 177 | ); 178 | runOnlyForDeploymentPostprocessing = 0; 179 | }; 180 | /* End PBXSourcesBuildPhase section */ 181 | 182 | /* Begin PBXVariantGroup section */ 183 | 2B9AD6A71D14DD6D00A81DB5 /* Main.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | 2B9AD6A81D14DD6D00A81DB5 /* Base */, 187 | ); 188 | name = Main.storyboard; 189 | sourceTree = ""; 190 | }; 191 | 2B9AD6AF1D14DD6D00A81DB5 /* LaunchScreen.storyboard */ = { 192 | isa = PBXVariantGroup; 193 | children = ( 194 | 2B9AD6B01D14DD6D00A81DB5 /* Base */, 195 | ); 196 | name = LaunchScreen.storyboard; 197 | sourceTree = ""; 198 | }; 199 | /* End PBXVariantGroup section */ 200 | 201 | /* Begin XCBuildConfiguration section */ 202 | 2B9AD6B31D14DD6D00A81DB5 /* Debug */ = { 203 | isa = XCBuildConfiguration; 204 | buildSettings = { 205 | ALWAYS_SEARCH_USER_PATHS = NO; 206 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 207 | CLANG_CXX_LIBRARY = "libc++"; 208 | CLANG_ENABLE_MODULES = YES; 209 | CLANG_ENABLE_OBJC_ARC = YES; 210 | CLANG_WARN_BOOL_CONVERSION = YES; 211 | CLANG_WARN_CONSTANT_CONVERSION = YES; 212 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 213 | CLANG_WARN_EMPTY_BODY = YES; 214 | CLANG_WARN_ENUM_CONVERSION = YES; 215 | CLANG_WARN_INT_CONVERSION = YES; 216 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 217 | CLANG_WARN_UNREACHABLE_CODE = YES; 218 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 219 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 220 | COPY_PHASE_STRIP = NO; 221 | DEBUG_INFORMATION_FORMAT = dwarf; 222 | ENABLE_STRICT_OBJC_MSGSEND = YES; 223 | ENABLE_TESTABILITY = YES; 224 | GCC_C_LANGUAGE_STANDARD = gnu99; 225 | GCC_DYNAMIC_NO_PIC = NO; 226 | GCC_NO_COMMON_BLOCKS = YES; 227 | GCC_OPTIMIZATION_LEVEL = 0; 228 | GCC_PREPROCESSOR_DEFINITIONS = ( 229 | "DEBUG=1", 230 | "$(inherited)", 231 | ); 232 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 233 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 234 | GCC_WARN_UNDECLARED_SELECTOR = YES; 235 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 236 | GCC_WARN_UNUSED_FUNCTION = YES; 237 | GCC_WARN_UNUSED_VARIABLE = YES; 238 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 239 | MTL_ENABLE_DEBUG_INFO = YES; 240 | ONLY_ACTIVE_ARCH = YES; 241 | SDKROOT = iphoneos; 242 | TARGETED_DEVICE_FAMILY = "1,2"; 243 | }; 244 | name = Debug; 245 | }; 246 | 2B9AD6B41D14DD6D00A81DB5 /* Release */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 251 | CLANG_CXX_LIBRARY = "libc++"; 252 | CLANG_ENABLE_MODULES = YES; 253 | CLANG_ENABLE_OBJC_ARC = YES; 254 | CLANG_WARN_BOOL_CONVERSION = YES; 255 | CLANG_WARN_CONSTANT_CONVERSION = YES; 256 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 257 | CLANG_WARN_EMPTY_BODY = YES; 258 | CLANG_WARN_ENUM_CONVERSION = YES; 259 | CLANG_WARN_INT_CONVERSION = YES; 260 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 261 | CLANG_WARN_UNREACHABLE_CODE = YES; 262 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 263 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 264 | COPY_PHASE_STRIP = NO; 265 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 266 | ENABLE_NS_ASSERTIONS = NO; 267 | ENABLE_STRICT_OBJC_MSGSEND = YES; 268 | GCC_C_LANGUAGE_STANDARD = gnu99; 269 | GCC_NO_COMMON_BLOCKS = YES; 270 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 271 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 272 | GCC_WARN_UNDECLARED_SELECTOR = YES; 273 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 274 | GCC_WARN_UNUSED_FUNCTION = YES; 275 | GCC_WARN_UNUSED_VARIABLE = YES; 276 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 277 | MTL_ENABLE_DEBUG_INFO = NO; 278 | SDKROOT = iphoneos; 279 | TARGETED_DEVICE_FAMILY = "1,2"; 280 | VALIDATE_PRODUCT = YES; 281 | }; 282 | name = Release; 283 | }; 284 | 2B9AD6B61D14DD6D00A81DB5 /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 288 | INFOPLIST_FILE = ZLCWebView/Info.plist; 289 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 290 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 291 | PRODUCT_BUNDLE_IDENTIFIER = zhailiuchuang.ZLCWebView; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | }; 294 | name = Debug; 295 | }; 296 | 2B9AD6B71D14DD6D00A81DB5 /* Release */ = { 297 | isa = XCBuildConfiguration; 298 | buildSettings = { 299 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 300 | INFOPLIST_FILE = ZLCWebView/Info.plist; 301 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 302 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 303 | PRODUCT_BUNDLE_IDENTIFIER = zhailiuchuang.ZLCWebView; 304 | PRODUCT_NAME = "$(TARGET_NAME)"; 305 | }; 306 | name = Release; 307 | }; 308 | /* End XCBuildConfiguration section */ 309 | 310 | /* Begin XCConfigurationList section */ 311 | 2B9AD6961D14DD6C00A81DB5 /* Build configuration list for PBXProject "ZLCWebView" */ = { 312 | isa = XCConfigurationList; 313 | buildConfigurations = ( 314 | 2B9AD6B31D14DD6D00A81DB5 /* Debug */, 315 | 2B9AD6B41D14DD6D00A81DB5 /* Release */, 316 | ); 317 | defaultConfigurationIsVisible = 0; 318 | defaultConfigurationName = Release; 319 | }; 320 | 2B9AD6B51D14DD6D00A81DB5 /* Build configuration list for PBXNativeTarget "ZLCWebView" */ = { 321 | isa = XCConfigurationList; 322 | buildConfigurations = ( 323 | 2B9AD6B61D14DD6D00A81DB5 /* Debug */, 324 | 2B9AD6B71D14DD6D00A81DB5 /* Release */, 325 | ); 326 | defaultConfigurationIsVisible = 0; 327 | defaultConfigurationName = Release; 328 | }; 329 | /* End XCConfigurationList section */ 330 | 331 | /* Begin XCVersionGroup section */ 332 | 2B9AD6AA1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodeld */ = { 333 | isa = XCVersionGroup; 334 | children = ( 335 | 2B9AD6AB1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodel */, 336 | ); 337 | currentVersion = 2B9AD6AB1D14DD6D00A81DB5 /* ZLCWebView.xcdatamodel */; 338 | path = ZLCWebView.xcdatamodeld; 339 | sourceTree = ""; 340 | versionGroupType = wrapper.xcdatamodel; 341 | }; 342 | /* End XCVersionGroup section */ 343 | }; 344 | rootObject = 2B9AD6931D14DD6C00A81DB5 /* Project object */; 345 | } 346 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/project.xcworkspace/xcuserdata/shining3d.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lczhai/ZLCWebView/79efc7825073067317573c04ae246b8600631a2b/ZLCWebView.xcodeproj/project.xcworkspace/xcuserdata/shining3d.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/project.xcworkspace/xcuserdata/zhailiuchuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lczhai/ZLCWebView/79efc7825073067317573c04ae246b8600631a2b/ZLCWebView.xcodeproj/project.xcworkspace/xcuserdata/zhailiuchuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/xcuserdata/shining3d.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/xcuserdata/shining3d.xcuserdatad/xcschemes/ZLCWebView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/xcuserdata/shining3d.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ZLCWebView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 2B9AD69A1D14DD6C00A81DB5 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/xcuserdata/zhailiuchuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/xcuserdata/zhailiuchuang.xcuserdatad/xcschemes/ZLCWebView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /ZLCWebView.xcodeproj/xcuserdata/zhailiuchuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ZLCWebView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 2B9AD69A1D14DD6C00A81DB5 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ZLCWebView/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lczhai/ZLCWebView/79efc7825073067317573c04ae246b8600631a2b/ZLCWebView/.DS_Store -------------------------------------------------------------------------------- /ZLCWebView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ZLCWebView 4 | // 5 | // Created by 翟留闯 on 16/6/18. 6 | // Copyright © 2016年 翟留闯. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (strong, nonatomic) UIWindow *window; 15 | 16 | @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; 17 | @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; 18 | @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; 19 | 20 | - (void)saveContext; 21 | - (NSURL *)applicationDocumentsDirectory; 22 | 23 | 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /ZLCWebView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ZLCWebView 4 | // 5 | // Created by 翟留闯 on 16/6/18. 6 | // Copyright © 2016年 翟留闯. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | 21 | 22 | ViewController *root = [[ViewController alloc]init]; 23 | UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:root]; 24 | self.window.rootViewController = nav; 25 | 26 | return YES; 27 | } 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 32 | } 33 | 34 | - (void)applicationDidEnterBackground:(UIApplication *)application { 35 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 36 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 37 | } 38 | 39 | - (void)applicationWillEnterForeground:(UIApplication *)application { 40 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 41 | } 42 | 43 | - (void)applicationDidBecomeActive:(UIApplication *)application { 44 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 45 | } 46 | 47 | - (void)applicationWillTerminate:(UIApplication *)application { 48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 49 | // Saves changes in the application's managed object context before the application terminates. 50 | [self saveContext]; 51 | } 52 | 53 | #pragma mark - Core Data stack 54 | 55 | @synthesize managedObjectContext = _managedObjectContext; 56 | @synthesize managedObjectModel = _managedObjectModel; 57 | @synthesize persistentStoreCoordinator = _persistentStoreCoordinator; 58 | 59 | - (NSURL *)applicationDocumentsDirectory { 60 | // The directory the application uses to store the Core Data store file. This code uses a directory named "zhailiuchuang.ZLCWebView" in the application's documents directory. 61 | return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 62 | } 63 | 64 | - (NSManagedObjectModel *)managedObjectModel { 65 | // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. 66 | if (_managedObjectModel != nil) { 67 | return _managedObjectModel; 68 | } 69 | NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"ZLCWebView" withExtension:@"momd"]; 70 | _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 71 | return _managedObjectModel; 72 | } 73 | 74 | - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 75 | // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. 76 | if (_persistentStoreCoordinator != nil) { 77 | return _persistentStoreCoordinator; 78 | } 79 | 80 | // Create the coordinator and store 81 | 82 | _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 83 | NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ZLCWebView.sqlite"]; 84 | NSError *error = nil; 85 | NSString *failureReason = @"There was an error creating or loading the application's saved data."; 86 | if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 87 | // Report any error we got. 88 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 89 | dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data"; 90 | dict[NSLocalizedFailureReasonErrorKey] = failureReason; 91 | dict[NSUnderlyingErrorKey] = error; 92 | error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; 93 | // Replace this with code to handle the error appropriately. 94 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 95 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 96 | abort(); 97 | } 98 | 99 | return _persistentStoreCoordinator; 100 | } 101 | 102 | 103 | - (NSManagedObjectContext *)managedObjectContext { 104 | // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) 105 | if (_managedObjectContext != nil) { 106 | return _managedObjectContext; 107 | } 108 | 109 | NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; 110 | if (!coordinator) { 111 | return nil; 112 | } 113 | _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; 114 | [_managedObjectContext setPersistentStoreCoordinator:coordinator]; 115 | return _managedObjectContext; 116 | } 117 | 118 | #pragma mark - Core Data Saving support 119 | 120 | - (void)saveContext { 121 | NSManagedObjectContext *managedObjectContext = self.managedObjectContext; 122 | if (managedObjectContext != nil) { 123 | NSError *error = nil; 124 | if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { 125 | // Replace this implementation with code to handle the error appropriately. 126 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 127 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 128 | abort(); 129 | } 130 | } 131 | } 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /ZLCWebView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ZLCWebView/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /ZLCWebView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /ZLCWebView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | NSAppTransportSecurity 47 | 48 | NSAllowsArbitraryLoads 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /ZLCWebView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ZLCWebView 4 | // 5 | // Created by 翟留闯 on 16/6/18. 6 | // Copyright © 2016年 翟留闯. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ZLCWebView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ZLCWebView 4 | // 5 | // Created by 翟留闯 on 16/6/18. 6 | // Copyright © 2016年 翟留闯. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ZLCWebView.h" 11 | 12 | #define isiOS8 __IPHONE_OS_VERSION_MAX_ALLOWED>=__IPHONE_8_0 13 | 14 | @interface ViewController () 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | { 20 | NSString *_urlStr; 21 | } 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | self.title = @"ZLCWebView"; 25 | _urlStr = @"http://www.baidu.com"; 26 | 27 | 28 | 29 | 30 | ZLCWebView *my = [[ZLCWebView alloc]initWithFrame:self.view.bounds]; 31 | 32 | 33 | // //获取本地缓存路径及获取页面缓存的html(慎用) 34 | // NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) objectAtIndex:0]; 35 | // NSString * path = [cachesPath stringByAppendingString:[NSString stringWithFormat:@"/Caches/%u.html",(unsigned)[_urlStr hash]]]; 36 | // NSString *htmlString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 37 | // 38 | // //判断是否加载过(是否已缓存过) 39 | // if (!(htmlString ==nil || [htmlString isEqualToString:@""])) { 40 | // [my loadHTMLString:htmlString]; 41 | // }else{ 42 | // NSURL *url = [NSURL URLWithString:_urlStr]; 43 | // NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:2 timeoutInterval:5]; 44 | // [my loadRequest:request]; 45 | // [self writeToCache]; 46 | // } 47 | 48 | NSURL *url = [NSURL URLWithString:_urlStr]; 49 | NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:2 timeoutInterval:5]; 50 | [my loadRequest:request]; 51 | 52 | my.delegate = self; 53 | [self.view addSubview:my]; 54 | 55 | 56 | 57 | } 58 | 59 | /** 60 | * 网页缓存写入文件 61 | */ 62 | - (void)writeToCache 63 | { 64 | NSString * htmlResponseStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:_urlStr] encoding:NSUTF8StringEncoding error:Nil]; 65 | //创建文件管理器 66 | NSFileManager *fileManager = [[NSFileManager alloc]init]; 67 | //获取document路径 68 | NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 69 | [fileManager createDirectoryAtPath:[cachesPath stringByAppendingString:@"/Caches"] withIntermediateDirectories:YES attributes:nil error:nil]; 70 | //写入路径 71 | NSString * path = [cachesPath stringByAppendingString:[NSString stringWithFormat:@"/Caches/%u.html",(unsigned)[_urlStr hash]]]; 72 | 73 | [htmlResponseStr writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil]; 74 | } 75 | 76 | 77 | 78 | - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview 79 | { 80 | NSLog(@"页面开始加载"); 81 | } 82 | 83 | - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL 84 | { 85 | NSLog(@"截取到URL:%@",URL); 86 | } 87 | - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL 88 | { 89 | NSLog(@"页面加载完成"); 90 | 91 | } 92 | 93 | - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error 94 | { 95 | NSLog(@"加载出现错误"); 96 | } 97 | 98 | 99 | - (void)didReceiveMemoryWarning { 100 | [super didReceiveMemoryWarning]; 101 | // Dispose of any resources that can be recreated. 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /ZLCWebView/ZLCWebView Resource/ZLCWebView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZLCWebView.h 3 | // 测试 4 | // 5 | // Created by shining3d on 16/6/17. 6 | // Copyright © 2016年 shining3d. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class ZLCWebView; 13 | @protocol ZLCWebViewDelegate 14 | @optional 15 | - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL; 16 | - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error; 17 | - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL; 18 | - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview; 19 | @end 20 | 21 | @interface ZLCWebView : UIView 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | #pragma mark - Public Properties 32 | 33 | //zlcdelegate 34 | @property (nonatomic, weak) id delegate; 35 | 36 | // The main and only UIProgressView 37 | @property (nonatomic, strong) UIProgressView *progressView; 38 | // The web views 39 | // Depending on the version of iOS, one of these will be set 40 | @property (nonatomic, strong) WKWebView *wkWebView; 41 | @property (nonatomic, strong) UIWebView *uiWebView; 42 | 43 | 44 | 45 | #pragma mark - Initializers view 46 | - (instancetype)initWithFrame:(CGRect)frame; 47 | 48 | 49 | #pragma mark - Static Initializers 50 | @property (nonatomic, strong) UIBarButtonItem *actionButton; 51 | @property (nonatomic, strong) UIColor *tintColor; 52 | @property (nonatomic, strong) UIColor *barTintColor; 53 | @property (nonatomic, assign) BOOL actionButtonHidden; 54 | @property (nonatomic, assign) BOOL showsURLInNavigationBar; 55 | @property (nonatomic, assign) BOOL showsPageTitleInNavigationBar; 56 | 57 | //Allow for custom activities in the browser by populating this optional array 58 | @property (nonatomic, strong) NSArray *customActivityItems; 59 | 60 | #pragma mark - Public Interface 61 | 62 | 63 | // Load a NSURLURLRequest to web view 64 | // Can be called any time after initialization 65 | - (void)loadRequest:(NSURLRequest *)request; 66 | 67 | // Load a NSURL to web view 68 | // Can be called any time after initialization 69 | - (void)loadURL:(NSURL *)URL; 70 | 71 | // Loads a URL as NSString to web view 72 | // Can be called any time after initialization 73 | - (void)loadURLString:(NSString *)URLString; 74 | 75 | 76 | // Loads an string containing HTML to web view 77 | // Can be called any time after initialization 78 | - (void)loadHTMLString:(NSString *)HTMLString; 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /ZLCWebView/ZLCWebView Resource/ZLCWebView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZLCWebView.m 3 | // 测试 4 | // 5 | // Created by shining3d on 16/6/17. 6 | // Copyright © 2016年 shining3d. All rights reserved. 7 | // 8 | 9 | #import "ZLCWebView.h" 10 | 11 | #define isiOS8 [[[UIDevice currentDevice] systemVersion] floatValue]>=8.0 12 | static void *ZLCWebBrowserContext = &ZLCWebBrowserContext; 13 | 14 | 15 | @interface ZLCWebView () 16 | @property (nonatomic, strong) NSTimer *fakeProgressTimer; 17 | @property (nonatomic, assign) BOOL uiWebViewIsLoading; 18 | @property (nonatomic, strong) NSURL *uiWebViewCurrentURL; 19 | @property (nonatomic, strong) NSURL *URLToLaunchWithPermission; 20 | @property (nonatomic, strong) UIAlertView *externalAppPermissionAlertView; 21 | 22 | 23 | @end 24 | 25 | 26 | 27 | @implementation ZLCWebView 28 | 29 | 30 | 31 | 32 | #pragma mark --Initializers 33 | - (instancetype)initWithFrame:(CGRect)frame 34 | { 35 | self = [super initWithFrame:frame]; 36 | if (self) { 37 | 38 | 39 | if(isiOS8) { 40 | 41 | self.wkWebView = [[WKWebView alloc] init]; 42 | 43 | } 44 | else { 45 | self.uiWebView = [[UIWebView alloc] init]; 46 | } 47 | 48 | 49 | self.backgroundColor = [UIColor redColor]; 50 | 51 | if(self.wkWebView) { 52 | [self.wkWebView setFrame:frame]; 53 | [self.wkWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 54 | [self.wkWebView setNavigationDelegate:self]; 55 | [self.wkWebView setUIDelegate:self]; 56 | [self.wkWebView setMultipleTouchEnabled:YES]; 57 | [self.wkWebView setAutoresizesSubviews:YES]; 58 | [self.wkWebView.scrollView setAlwaysBounceVertical:YES]; 59 | [self addSubview:self.wkWebView]; 60 | self.wkWebView.scrollView.bounces = NO; 61 | [self.wkWebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:ZLCWebBrowserContext]; 62 | } 63 | else { 64 | [self.uiWebView setFrame:frame]; 65 | [self.uiWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 66 | [self.uiWebView setDelegate:self]; 67 | [self.uiWebView setMultipleTouchEnabled:YES]; 68 | [self.uiWebView setAutoresizesSubviews:YES]; 69 | [self.uiWebView setScalesPageToFit:YES]; 70 | [self.uiWebView.scrollView setAlwaysBounceVertical:YES]; 71 | self.uiWebView.scrollView.bounces = NO; 72 | [self addSubview:self.uiWebView]; 73 | } 74 | 75 | 76 | 77 | 78 | 79 | self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; 80 | [self.progressView setTrackTintColor:[UIColor colorWithWhite:1.0f alpha:0.0f]]; 81 | [self.progressView setFrame:CGRectMake(0, 64, self.frame.size.width, self.progressView.frame.size.height)]; 82 | 83 | //设置进度条颜色 84 | [self setTintColor:[UIColor colorWithRed:0.400 green:0.863 blue:0.133 alpha:1.000]]; 85 | [self addSubview:self.progressView]; 86 | 87 | 88 | } 89 | return self; 90 | } 91 | 92 | 93 | 94 | #pragma mark - Public Interface 95 | - (void)loadRequest:(NSURLRequest *)request { 96 | if(self.wkWebView) { 97 | [self.wkWebView loadRequest:request]; 98 | } 99 | else { 100 | [self.uiWebView loadRequest:request]; 101 | 102 | 103 | } 104 | } 105 | 106 | - (void)loadURL:(NSURL *)URL { 107 | [self loadRequest:[NSURLRequest requestWithURL:URL]]; 108 | } 109 | 110 | - (void)loadURLString:(NSString *)URLString { 111 | NSURL *URL = [NSURL URLWithString:URLString]; 112 | [self loadURL:URL]; 113 | } 114 | 115 | - (void)loadHTMLString:(NSString *)HTMLString { 116 | if(self.wkWebView) { 117 | [self.wkWebView loadHTMLString:HTMLString baseURL:nil]; 118 | } 119 | else if(self.uiWebView) { 120 | [self.uiWebView loadHTMLString:HTMLString baseURL:nil]; 121 | } 122 | } 123 | 124 | 125 | 126 | - (void)setTintColor:(UIColor *)tintColor { 127 | _tintColor = tintColor; 128 | [self.progressView setTintColor:tintColor]; 129 | } 130 | 131 | - (void)setBarTintColor:(UIColor *)barTintColor { 132 | _barTintColor = barTintColor; 133 | } 134 | 135 | 136 | 137 | #pragma mark - UIWebViewDelegate 138 | 139 | - (void)webViewDidStartLoad:(UIWebView *)webView 140 | { 141 | if(webView == self.uiWebView) { 142 | [self.delegate zlcwebViewDidStartLoad:self]; 143 | 144 | } 145 | } 146 | 147 | //监视请求 148 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 149 | 150 | if(webView == self.uiWebView) { 151 | 152 | if(![self externalAppRequiredToOpenURL:request.URL]) { 153 | self.uiWebViewCurrentURL = request.URL; 154 | self.uiWebViewIsLoading = YES; 155 | 156 | [self fakeProgressViewStartLoading]; 157 | 158 | 159 | //back delegate 160 | [self.delegate zlcwebView:self shouldStartLoadWithURL:request.URL]; 161 | return YES; 162 | } 163 | else { 164 | [self launchExternalAppWithURL:request.URL]; 165 | return NO; 166 | } 167 | } 168 | return NO; 169 | } 170 | 171 | 172 | - (void)webViewDidFinishLoad:(UIWebView *)webView { 173 | 174 | 175 | if(webView == self.uiWebView) { 176 | if(!self.uiWebView.isLoading) { 177 | self.uiWebViewIsLoading = NO; 178 | 179 | [self fakeProgressBarStopLoading]; 180 | } 181 | 182 | //back delegate 183 | [self.delegate zlcwebView:self didFinishLoadingURL:self.uiWebView.request.URL]; 184 | 185 | } 186 | } 187 | 188 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 189 | 190 | if(webView == self.uiWebView) { 191 | if(!self.uiWebView.isLoading) { 192 | self.uiWebViewIsLoading = NO; 193 | 194 | [self fakeProgressBarStopLoading]; 195 | } 196 | 197 | //back delegate 198 | [self.delegate zlcwebView:self didFailToLoadURL:self.uiWebView.request.URL error:error]; 199 | } 200 | } 201 | 202 | 203 | #pragma mark - WKNavigationDelegate 204 | 205 | 206 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { 207 | if(webView == self.wkWebView) { 208 | 209 | 210 | 211 | 212 | //back delegate 213 | [self.delegate zlcwebViewDidStartLoad:self]; 214 | 215 | 216 | // WKNavigationActionPolicy(WKNavigationActionPolicyAllow); 217 | 218 | } 219 | } 220 | 221 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { 222 | 223 | if(webView == self.wkWebView) { 224 | 225 | //back delegate 226 | [self.delegate zlcwebView:self didFinishLoadingURL:self.wkWebView.URL]; 227 | } 228 | } 229 | 230 | - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation 231 | withError:(NSError *)error { 232 | if(webView == self.wkWebView) { 233 | //back delegate 234 | [self.delegate zlcwebView:self didFailToLoadURL:self.wkWebView.URL error:error]; 235 | } 236 | 237 | } 238 | 239 | - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation 240 | withError:(NSError *)error { 241 | if(webView == self.wkWebView) { 242 | //back delegate 243 | [self.delegate zlcwebView:self didFailToLoadURL:self.wkWebView.URL error:error]; 244 | } 245 | } 246 | 247 | - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { 248 | 249 | 250 | if(webView == self.wkWebView) { 251 | 252 | NSURL *URL = navigationAction.request.URL; 253 | if(![self externalAppRequiredToOpenURL:URL]) { 254 | if(!navigationAction.targetFrame) { 255 | [self loadURL:URL]; 256 | decisionHandler(WKNavigationActionPolicyCancel); 257 | return; 258 | } 259 | [self callback_webViewShouldStartLoadWithRequest:navigationAction.request navigationType:navigationAction.navigationType]; 260 | 261 | } 262 | else if([[UIApplication sharedApplication] canOpenURL:URL]) { 263 | [self launchExternalAppWithURL:URL]; 264 | decisionHandler(WKNavigationActionPolicyCancel); 265 | return; 266 | } 267 | } 268 | 269 | 270 | 271 | decisionHandler(WKNavigationActionPolicyAllow); 272 | 273 | 274 | } 275 | 276 | -(BOOL)callback_webViewShouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(NSInteger)navigationType 277 | { 278 | //back delegate 279 | [self.delegate zlcwebView:self shouldStartLoadWithURL:request.URL]; 280 | return YES; 281 | } 282 | 283 | 284 | #pragma mark - WKUIDelegate 285 | 286 | - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{ 287 | if (!navigationAction.targetFrame.isMainFrame) { 288 | [webView loadRequest:navigationAction.request]; 289 | } 290 | return nil; 291 | } 292 | #pragma mark - Estimated Progress KVO (WKWebView) 293 | 294 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 295 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.wkWebView) { 296 | [self.progressView setAlpha:1.0f]; 297 | BOOL animated = self.wkWebView.estimatedProgress > self.progressView.progress; 298 | [self.progressView setProgress:self.wkWebView.estimatedProgress animated:animated]; 299 | 300 | // Once complete, fade out UIProgressView 301 | if(self.wkWebView.estimatedProgress >= 1.0f) { 302 | [UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{ 303 | [self.progressView setAlpha:0.0f]; 304 | } completion:^(BOOL finished) { 305 | [self.progressView setProgress:0.0f animated:NO]; 306 | }]; 307 | } 308 | } 309 | else { 310 | [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; 311 | } 312 | } 313 | 314 | #pragma mark - Fake Progress Bar Control (UIWebView) 315 | 316 | - (void)fakeProgressViewStartLoading { 317 | [self.progressView setProgress:0.0f animated:NO]; 318 | [self.progressView setAlpha:1.0f]; 319 | 320 | if(!self.fakeProgressTimer) { 321 | self.fakeProgressTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(fakeProgressTimerDidFire:) userInfo:nil repeats:YES]; 322 | } 323 | } 324 | 325 | - (void)fakeProgressBarStopLoading { 326 | if(self.fakeProgressTimer) { 327 | [self.fakeProgressTimer invalidate]; 328 | } 329 | 330 | if(self.progressView) { 331 | [self.progressView setProgress:1.0f animated:YES]; 332 | [UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{ 333 | [self.progressView setAlpha:0.0f]; 334 | } completion:^(BOOL finished) { 335 | [self.progressView setProgress:0.0f animated:NO]; 336 | }]; 337 | } 338 | } 339 | 340 | - (void)fakeProgressTimerDidFire:(id)sender { 341 | CGFloat increment = 0.005/(self.progressView.progress + 0.2); 342 | if([self.uiWebView isLoading]) { 343 | CGFloat progress = (self.progressView.progress < 0.75f) ? self.progressView.progress + increment : self.progressView.progress + 0.0005; 344 | if(self.progressView.progress < 0.95) { 345 | [self.progressView setProgress:progress animated:YES]; 346 | } 347 | } 348 | } 349 | 350 | #pragma mark - External App Support 351 | - (BOOL)externalAppRequiredToOpenURL:(NSURL *)URL { 352 | 353 | //若需要限制只允许某些前缀的scheme通过请求,则取消下述注释,并在数组内添加自己需要放行的前缀 354 | // NSSet *validSchemes = [NSSet setWithArray:@[@"http", @"https",@"file"]]; 355 | // return ![validSchemes containsObject:URL.scheme]; 356 | 357 | return !URL; 358 | } 359 | 360 | - (void)launchExternalAppWithURL:(NSURL *)URL { 361 | self.URLToLaunchWithPermission = URL; 362 | if (![self.externalAppPermissionAlertView isVisible]) { 363 | [self.externalAppPermissionAlertView show]; 364 | } 365 | 366 | } 367 | 368 | #pragma mark - UIAlertViewDelegate 369 | 370 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 371 | if(alertView == self.externalAppPermissionAlertView) { 372 | if(buttonIndex != alertView.cancelButtonIndex) { 373 | [[UIApplication sharedApplication] openURL:self.URLToLaunchWithPermission]; 374 | } 375 | self.URLToLaunchWithPermission = nil; 376 | } 377 | } 378 | 379 | #pragma mark - Dealloc 380 | 381 | - (void)dealloc { 382 | [self.uiWebView setDelegate:nil]; 383 | [self.wkWebView setNavigationDelegate:nil]; 384 | [self.wkWebView setUIDelegate:nil]; 385 | [self.wkWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))]; 386 | 387 | } 388 | 389 | @end 390 | -------------------------------------------------------------------------------- /ZLCWebView/ZLCWebView.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | ZLCWebView.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /ZLCWebView/ZLCWebView.xcdatamodeld/ZLCWebView.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ZLCWebView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ZLCWebView 4 | // 5 | // Created by 翟留闯 on 16/6/18. 6 | // Copyright © 2016年 翟留闯. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------