├── .gitignore ├── Classes ├── IMYWebView.h ├── IMYWebView.m └── UIWebViewProgress │ ├── IMY_NJKWebViewProgress.h │ └── IMY_NJKWebViewProgress.m ├── IMYWebView.podspec.json ├── IMYWebView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── IMYWebView ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── FirstViewController.h ├── FirstViewController.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── first.imageset │ │ ├── Contents.json │ │ └── first.pdf │ └── second.imageset │ │ ├── Contents.json │ │ └── second.pdf ├── Info.plist ├── SecondViewController.h ├── SecondViewController.m └── main.m ├── IMYWebViewTests ├── IMYWebViewTests.m └── Info.plist ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /Classes/IMYWebView.h: -------------------------------------------------------------------------------- 1 | // 2 | // IMYWebView.h 3 | // IMY_ViewKit 4 | // 5 | // Created by ljh on 15/7/1. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol WKScriptMessageHandler; 12 | @class IMYWebView, JSContext; 13 | 14 | @protocol IMYWebViewDelegate 15 | @optional 16 | 17 | - (void)webViewDidStartLoad:(IMYWebView*)webView; 18 | - (void)webViewDidFinishLoad:(IMYWebView*)webView; 19 | - (void)webView:(IMYWebView*)webView didFailLoadWithError:(NSError*)error; 20 | - (BOOL)webView:(IMYWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType; 21 | 22 | @end 23 | 24 | ///无缝切换UIWebView 会根据系统版本自动选择 使用WKWebView 还是 UIWebView 25 | @interface IMYWebView : UIView 26 | 27 | ///使用UIWebView 28 | - (instancetype)initWithFrame:(CGRect)frame usingUIWebView:(BOOL)usingUIWebView; 29 | 30 | ///会转接 WKUIDelegate,WKNavigationDelegate 内部未实现的回调。 31 | @property (weak, nonatomic) id delegate; 32 | 33 | ///内部使用的webView 34 | @property (nonatomic, readonly) id realWebView; 35 | ///是否正在使用 UIWebView 36 | @property (nonatomic, readonly) BOOL usingUIWebView; 37 | ///预估网页加载进度 38 | @property (nonatomic, readonly) double estimatedProgress; 39 | 40 | @property (nonatomic, readonly) NSURLRequest* originRequest; 41 | 42 | ///只有ios7以上的UIWebView才能获取到,WKWebView 请使用下面的方法. 43 | @property (nonatomic, readonly) JSContext* jsContext; 44 | ///WKWebView 跟网页进行交互的方法。 45 | - (void)addScriptMessageHandler:(id)scriptMessageHandler name:(NSString*)name; 46 | 47 | ///back 层数 48 | - (NSInteger)countOfHistory; 49 | - (void)gobackWithStep:(NSInteger)step; 50 | 51 | ///---- UI 或者 WK 的API 52 | @property (nonatomic, readonly) UIScrollView* scrollView; 53 | 54 | - (id)loadRequest:(NSURLRequest*)request; 55 | - (id)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL; 56 | 57 | @property (nonatomic, readonly, copy) NSString* title; 58 | @property (nonatomic, readonly) NSURLRequest* currentRequest; 59 | @property (nonatomic, readonly) NSURL* URL; 60 | 61 | @property (nonatomic, readonly, getter=isLoading) BOOL loading; 62 | @property (nonatomic, readonly) BOOL canGoBack; 63 | @property (nonatomic, readonly) BOOL canGoForward; 64 | 65 | - (id)goBack; 66 | - (id)goForward; 67 | - (id)reload; 68 | - (id)reloadFromOrigin; 69 | - (void)stopLoading; 70 | 71 | - (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler; 72 | ///不建议使用这个办法 因为会在内部等待webView 的执行结果 73 | - (NSString*)stringByEvaluatingJavaScriptFromString:(NSString*)javaScriptString __deprecated_msg("Method deprecated. Use [evaluateJavaScript:completionHandler:]"); 74 | 75 | ///是否根据视图大小来缩放页面 默认为YES 76 | @property (nonatomic) BOOL scalesPageToFit; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /Classes/IMYWebView.m: -------------------------------------------------------------------------------- 1 | // 2 | // IMYWebView.m 3 | // IMY_ViewKit 4 | // 5 | // Created by ljh on 15/7/1. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import "IMYWebView.h" 10 | 11 | #import "IMY_NJKWebViewProgress.h" 12 | #import 13 | #import 14 | #import 15 | 16 | @interface IMYWebView () 17 | 18 | @property (nonatomic, assign) double estimatedProgress; 19 | @property (nonatomic, strong) NSURLRequest* originRequest; 20 | @property (nonatomic, strong) NSURLRequest* currentRequest; 21 | 22 | @property (nonatomic, copy) NSString* title; 23 | 24 | @property (nonatomic, strong) IMY_NJKWebViewProgress* njkWebViewProgress; 25 | @end 26 | 27 | @implementation IMYWebView 28 | 29 | @synthesize usingUIWebView = _usingUIWebView; 30 | @synthesize realWebView = _realWebView; 31 | @synthesize scalesPageToFit = _scalesPageToFit; 32 | 33 | - (instancetype)initWithCoder:(NSCoder*)coder 34 | { 35 | self = [super initWithCoder:coder]; 36 | if (self) { 37 | [self _initMyself]; 38 | } 39 | return self; 40 | } 41 | - (instancetype)init 42 | { 43 | return [self initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 64)]; 44 | } 45 | - (instancetype)initWithFrame:(CGRect)frame 46 | { 47 | return [self initWithFrame:frame usingUIWebView:NO]; 48 | } 49 | - (instancetype)initWithFrame:(CGRect)frame usingUIWebView:(BOOL)usingUIWebView 50 | { 51 | self = [super initWithFrame:frame]; 52 | if (self) { 53 | _usingUIWebView = usingUIWebView; 54 | [self _initMyself]; 55 | } 56 | return self; 57 | } 58 | - (void)_initMyself 59 | { 60 | Class wkWebView = NSClassFromString(@"WKWebView"); 61 | if (wkWebView && self.usingUIWebView == NO) { 62 | [self initWKWebView]; 63 | _usingUIWebView = NO; 64 | } 65 | else { 66 | [self initUIWebView]; 67 | _usingUIWebView = YES; 68 | } 69 | [self.realWebView addObserver:self forKeyPath:@"loading" options:NSKeyValueObservingOptionNew context:nil]; 70 | self.scalesPageToFit = YES; 71 | 72 | [self.realWebView setFrame:self.bounds]; 73 | [self.realWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 74 | [self addSubview:self.realWebView]; 75 | } 76 | - (void)setDelegate:(id)delegate 77 | { 78 | _delegate = delegate; 79 | if (_usingUIWebView) { 80 | UIWebView* webView = self.realWebView; 81 | webView.delegate = nil; 82 | webView.delegate = self; 83 | } 84 | else { 85 | WKWebView* webView = self.realWebView; 86 | webView.UIDelegate = nil; 87 | webView.navigationDelegate = nil; 88 | webView.UIDelegate = self; 89 | webView.navigationDelegate = self; 90 | } 91 | } 92 | - (void)initWKWebView 93 | { 94 | WKWebViewConfiguration* configuration = [[NSClassFromString(@"WKWebViewConfiguration") alloc] init]; 95 | configuration.userContentController = [NSClassFromString(@"WKUserContentController") new]; 96 | 97 | WKPreferences* preferences = [NSClassFromString(@"WKPreferences") new]; 98 | preferences.javaScriptCanOpenWindowsAutomatically = YES; 99 | configuration.preferences = preferences; 100 | 101 | WKWebView* webView = [[NSClassFromString(@"WKWebView") alloc] initWithFrame:self.bounds configuration:configuration]; 102 | webView.UIDelegate = self; 103 | webView.navigationDelegate = self; 104 | 105 | webView.backgroundColor = [UIColor clearColor]; 106 | webView.opaque = NO; 107 | 108 | [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; 109 | [webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil]; 110 | _realWebView = webView; 111 | } 112 | - (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context 113 | { 114 | if ([keyPath isEqualToString:@"estimatedProgress"]) { 115 | self.estimatedProgress = [change[NSKeyValueChangeNewKey] doubleValue]; 116 | } 117 | else if ([keyPath isEqualToString:@"title"]) { 118 | self.title = change[NSKeyValueChangeNewKey]; 119 | } 120 | else { 121 | [self willChangeValueForKey:keyPath]; 122 | [self didChangeValueForKey:keyPath]; 123 | } 124 | } 125 | - (void)initUIWebView 126 | { 127 | UIWebView* webView = [[UIWebView alloc] initWithFrame:self.bounds]; 128 | webView.backgroundColor = [UIColor clearColor]; 129 | webView.allowsInlineMediaPlayback = YES; 130 | webView.mediaPlaybackRequiresUserAction = NO; 131 | 132 | webView.opaque = NO; 133 | for (UIView* subview in [webView.scrollView subviews]) { 134 | if ([subview isKindOfClass:[UIImageView class]]) { 135 | ((UIImageView*)subview).image = nil; 136 | subview.backgroundColor = [UIColor clearColor]; 137 | } 138 | } 139 | 140 | self.njkWebViewProgress = [[IMY_NJKWebViewProgress alloc] init]; 141 | webView.delegate = _njkWebViewProgress; 142 | _njkWebViewProgress.webViewProxyDelegate = self; 143 | _njkWebViewProgress.progressDelegate = self; 144 | 145 | _realWebView = webView; 146 | } 147 | - (void)addScriptMessageHandler:(id)scriptMessageHandler name:(NSString *)name 148 | { 149 | if (!_usingUIWebView) { 150 | WKWebViewConfiguration* configuration = [(WKWebView*)self.realWebView configuration]; 151 | [configuration.userContentController addScriptMessageHandler:scriptMessageHandler name:name]; 152 | } 153 | } 154 | - (JSContext *)jsContext 155 | { 156 | if (_usingUIWebView) { 157 | return [(UIWebView*)self.realWebView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; 158 | } 159 | else { 160 | return nil; 161 | } 162 | } 163 | #pragma mark - UIWebViewDelegate 164 | 165 | - (void)webViewDidFinishLoad:(UIWebView*)webView 166 | { 167 | self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; 168 | if (self.originRequest == nil) { 169 | self.originRequest = webView.request; 170 | } 171 | [self callback_webViewDidFinishLoad]; 172 | } 173 | - (void)webViewDidStartLoad:(UIWebView*)webView 174 | { 175 | [self callback_webViewDidStartLoad]; 176 | } 177 | - (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error 178 | { 179 | [self callback_webViewDidFailLoadWithError:error]; 180 | } 181 | - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 182 | { 183 | BOOL resultBOOL = [self callback_webViewShouldStartLoadWithRequest:request navigationType:navigationType]; 184 | return resultBOOL; 185 | } 186 | - (void)webViewProgress:(IMY_NJKWebViewProgress*)webViewProgress updateProgress:(CGFloat)progress 187 | { 188 | self.estimatedProgress = progress; 189 | } 190 | #pragma mark - WKNavigationDelegate 191 | - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler 192 | { 193 | BOOL resultBOOL = [self callback_webViewShouldStartLoadWithRequest:navigationAction.request navigationType:navigationAction.navigationType]; 194 | BOOL isLoadingDisableScheme = [self isLoadingWKWebViewDisableScheme:navigationAction.request.URL]; 195 | 196 | if (resultBOOL && !isLoadingDisableScheme) { 197 | self.currentRequest = navigationAction.request; 198 | if (navigationAction.targetFrame == nil) { 199 | [webView loadRequest:navigationAction.request]; 200 | } 201 | decisionHandler(WKNavigationActionPolicyAllow); 202 | } 203 | else { 204 | decisionHandler(WKNavigationActionPolicyCancel); 205 | } 206 | } 207 | - (void)webView:(WKWebView*)webView didStartProvisionalNavigation:(WKNavigation*)navigation 208 | { 209 | [self callback_webViewDidStartLoad]; 210 | } 211 | - (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation 212 | { 213 | [self callback_webViewDidFinishLoad]; 214 | } 215 | - (void)webView:(WKWebView*)webView didFailProvisionalNavigation:(WKNavigation*)navigation withError:(NSError*)error 216 | { 217 | [self callback_webViewDidFailLoadWithError:error]; 218 | } 219 | - (void)webView:(WKWebView*)webView didFailNavigation:(WKNavigation*)navigation withError:(NSError*)error 220 | { 221 | [self callback_webViewDidFailLoadWithError:error]; 222 | } 223 | #pragma mark - WKUIDelegate 224 | ///-- 还没用到 225 | #pragma mark - CALLBACK IMYVKWebView Delegate 226 | 227 | - (void)callback_webViewDidFinishLoad 228 | { 229 | if ([self.delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { 230 | [self.delegate webViewDidFinishLoad:self]; 231 | } 232 | } 233 | - (void)callback_webViewDidStartLoad 234 | { 235 | if ([self.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) { 236 | [self.delegate webViewDidStartLoad:self]; 237 | } 238 | } 239 | - (void)callback_webViewDidFailLoadWithError:(NSError*)error 240 | { 241 | if ([self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { 242 | [self.delegate webView:self didFailLoadWithError:error]; 243 | } 244 | } 245 | - (BOOL)callback_webViewShouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(NSInteger)navigationType 246 | { 247 | BOOL resultBOOL = YES; 248 | if ([self.delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { 249 | if (navigationType == -1) { 250 | navigationType = UIWebViewNavigationTypeOther; 251 | } 252 | resultBOOL = [self.delegate webView:self shouldStartLoadWithRequest:request navigationType:navigationType]; 253 | } 254 | return resultBOOL; 255 | } 256 | 257 | #pragma mark - 基础方法 258 | ///判断当前加载的url是否是WKWebView不能打开的协议类型 259 | - (BOOL)isLoadingWKWebViewDisableScheme:(NSURL*)url 260 | { 261 | BOOL retValue = NO; 262 | 263 | //判断是否正在加载WKWebview不能识别的协议类型:phone numbers, email address, maps, etc. 264 | if ([url.scheme isEqualToString:@"tel"]) { 265 | UIApplication* app = [UIApplication sharedApplication]; 266 | if ([app canOpenURL:url]) { 267 | [app openURL:url]; 268 | retValue = YES; 269 | } 270 | } 271 | 272 | return retValue; 273 | } 274 | 275 | - (UIScrollView*)scrollView 276 | { 277 | return [(id)self.realWebView scrollView]; 278 | } 279 | 280 | - (id)loadRequest:(NSURLRequest*)request 281 | { 282 | self.originRequest = request; 283 | self.currentRequest = request; 284 | 285 | if (_usingUIWebView) { 286 | [(UIWebView*)self.realWebView loadRequest:request]; 287 | return nil; 288 | } 289 | else { 290 | return [(WKWebView*)self.realWebView loadRequest:request]; 291 | } 292 | } 293 | - (id)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL 294 | { 295 | if (_usingUIWebView) { 296 | [(UIWebView*)self.realWebView loadHTMLString:string baseURL:baseURL]; 297 | return nil; 298 | } 299 | else { 300 | return [(WKWebView*)self.realWebView loadHTMLString:string baseURL:baseURL]; 301 | } 302 | } 303 | - (NSURLRequest*)currentRequest 304 | { 305 | if (_usingUIWebView) { 306 | return [(UIWebView*)self.realWebView request]; 307 | ; 308 | } 309 | else { 310 | return _currentRequest; 311 | } 312 | } 313 | - (NSURL*)URL 314 | { 315 | if (_usingUIWebView) { 316 | return [(UIWebView*)self.realWebView request].URL; 317 | ; 318 | } 319 | else { 320 | return [(WKWebView*)self.realWebView URL]; 321 | } 322 | } 323 | - (BOOL)isLoading 324 | { 325 | return [self.realWebView isLoading]; 326 | } 327 | - (BOOL)canGoBack 328 | { 329 | return [self.realWebView canGoBack]; 330 | } 331 | - (BOOL)canGoForward 332 | { 333 | return [self.realWebView canGoForward]; 334 | } 335 | 336 | - (id)goBack 337 | { 338 | if (_usingUIWebView) { 339 | [(UIWebView*)self.realWebView goBack]; 340 | return nil; 341 | } 342 | else { 343 | return [(WKWebView*)self.realWebView goBack]; 344 | } 345 | } 346 | - (id)goForward 347 | { 348 | if (_usingUIWebView) { 349 | [(UIWebView*)self.realWebView goForward]; 350 | return nil; 351 | } 352 | else { 353 | return [(WKWebView*)self.realWebView goForward]; 354 | } 355 | } 356 | - (id)reload 357 | { 358 | if (_usingUIWebView) { 359 | [(UIWebView*)self.realWebView reload]; 360 | return nil; 361 | } 362 | else { 363 | return [(WKWebView*)self.realWebView reload]; 364 | } 365 | } 366 | - (id)reloadFromOrigin 367 | { 368 | if (_usingUIWebView) { 369 | if (self.originRequest) { 370 | [self evaluateJavaScript:[NSString stringWithFormat:@"window.location.replace('%@')", self.originRequest.URL.absoluteString] completionHandler:nil]; 371 | } 372 | return nil; 373 | } 374 | else { 375 | return [(WKWebView*)self.realWebView reloadFromOrigin]; 376 | } 377 | } 378 | - (void)stopLoading 379 | { 380 | [self.realWebView stopLoading]; 381 | } 382 | 383 | - (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler 384 | { 385 | if (_usingUIWebView) { 386 | NSString* result = [(UIWebView*)self.realWebView stringByEvaluatingJavaScriptFromString:javaScriptString]; 387 | if (completionHandler) { 388 | completionHandler(result, nil); 389 | } 390 | } 391 | else { 392 | return [(WKWebView*)self.realWebView evaluateJavaScript:javaScriptString completionHandler:completionHandler]; 393 | } 394 | } 395 | - (NSString*)stringByEvaluatingJavaScriptFromString:(NSString*)javaScriptString 396 | { 397 | if (_usingUIWebView) { 398 | NSString* result = [(UIWebView*)self.realWebView stringByEvaluatingJavaScriptFromString:javaScriptString]; 399 | return result; 400 | } 401 | else { 402 | __block NSString* result = nil; 403 | __block BOOL isExecuted = NO; 404 | [(WKWebView*)self.realWebView evaluateJavaScript:javaScriptString completionHandler:^(id obj, NSError* error) { 405 | result = obj; 406 | isExecuted = YES; 407 | }]; 408 | 409 | while (isExecuted == NO) { 410 | [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 411 | } 412 | return result; 413 | } 414 | } 415 | - (void)setScalesPageToFit:(BOOL)scalesPageToFit 416 | { 417 | if (_usingUIWebView) { 418 | UIWebView* webView = _realWebView; 419 | webView.scalesPageToFit = scalesPageToFit; 420 | } 421 | else { 422 | if (_scalesPageToFit == scalesPageToFit) { 423 | return; 424 | } 425 | 426 | WKWebView* webView = _realWebView; 427 | 428 | NSString* jScript = 429 | @"var head = document.getElementsByTagName('head')[0];\ 430 | var hasViewPort = 0;\ 431 | var metas = head.getElementsByTagName('meta');\ 432 | for (var i = metas.length; i>=0 ; i--) {\ 433 | var m = metas[i];\ 434 | if (m.name == 'viewport') {\ 435 | hasViewPort = 1;\ 436 | break;\ 437 | }\ 438 | }; \ 439 | if(hasViewPort == 0) { \ 440 | var meta = document.createElement('meta'); \ 441 | meta.name = 'viewport'; \ 442 | meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; \ 443 | head.appendChild(meta);\ 444 | }"; 445 | 446 | WKUserContentController *userContentController = webView.configuration.userContentController; 447 | NSMutableArray *array = [userContentController.userScripts mutableCopy]; 448 | WKUserScript* fitWKUScript = nil; 449 | for (WKUserScript* wkUScript in array) { 450 | if ([wkUScript.source isEqual:jScript]) { 451 | fitWKUScript = wkUScript; 452 | break; 453 | } 454 | } 455 | if (scalesPageToFit) { 456 | if (!fitWKUScript) { 457 | fitWKUScript = [[NSClassFromString(@"WKUserScript") alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO]; 458 | [userContentController addUserScript:fitWKUScript]; 459 | } 460 | } 461 | else { 462 | if (fitWKUScript) { 463 | [array removeObject:fitWKUScript]; 464 | } 465 | ///没法修改数组 只能移除全部 再重新添加 466 | [userContentController removeAllUserScripts]; 467 | for (WKUserScript* wkUScript in array) { 468 | [userContentController addUserScript:wkUScript]; 469 | } 470 | } 471 | } 472 | _scalesPageToFit = scalesPageToFit; 473 | } 474 | - (BOOL)scalesPageToFit 475 | { 476 | if (_usingUIWebView) { 477 | return [_realWebView scalesPageToFit]; 478 | } 479 | else { 480 | return _scalesPageToFit; 481 | } 482 | } 483 | 484 | - (NSInteger)countOfHistory 485 | { 486 | if (_usingUIWebView) { 487 | UIWebView* webView = self.realWebView; 488 | 489 | int count = [[webView stringByEvaluatingJavaScriptFromString:@"window.history.length"] intValue]; 490 | if (count) { 491 | return count; 492 | } 493 | else { 494 | return 1; 495 | } 496 | } 497 | else { 498 | WKWebView* webView = self.realWebView; 499 | return webView.backForwardList.backList.count; 500 | } 501 | } 502 | - (void)gobackWithStep:(NSInteger)step 503 | { 504 | if (self.canGoBack == NO) 505 | return; 506 | 507 | if (step > 0) { 508 | NSInteger historyCount = self.countOfHistory; 509 | if (step >= historyCount) { 510 | step = historyCount - 1; 511 | } 512 | 513 | if (_usingUIWebView) { 514 | UIWebView* webView = self.realWebView; 515 | [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.history.go(-%ld)", (long)step]]; 516 | } 517 | else { 518 | WKWebView* webView = self.realWebView; 519 | WKBackForwardListItem* backItem = webView.backForwardList.backList[step]; 520 | [webView goToBackForwardListItem:backItem]; 521 | } 522 | } 523 | else { 524 | [self goBack]; 525 | } 526 | } 527 | #pragma mark - 如果没有找到方法 去realWebView 中调用 528 | - (BOOL)respondsToSelector:(SEL)aSelector 529 | { 530 | BOOL hasResponds = [super respondsToSelector:aSelector]; 531 | if (hasResponds == NO) { 532 | hasResponds = [self.delegate respondsToSelector:aSelector]; 533 | } 534 | if (hasResponds == NO) { 535 | hasResponds = [self.realWebView respondsToSelector:aSelector]; 536 | } 537 | return hasResponds; 538 | } 539 | - (NSMethodSignature*)methodSignatureForSelector:(SEL)selector 540 | { 541 | NSMethodSignature* methodSign = [super methodSignatureForSelector:selector]; 542 | if (methodSign == nil) { 543 | if ([self.realWebView respondsToSelector:selector]) { 544 | methodSign = [self.realWebView methodSignatureForSelector:selector]; 545 | } 546 | else { 547 | methodSign = [(id)self.delegate methodSignatureForSelector:selector]; 548 | } 549 | } 550 | return methodSign; 551 | } 552 | - (void)forwardInvocation:(NSInvocation*)invocation 553 | { 554 | if ([self.realWebView respondsToSelector:invocation.selector]) { 555 | [invocation invokeWithTarget:self.realWebView]; 556 | } 557 | else { 558 | [invocation invokeWithTarget:self.delegate]; 559 | } 560 | } 561 | 562 | #pragma mark - 清理 563 | - (void)dealloc 564 | { 565 | if (_usingUIWebView) { 566 | UIWebView* webView = _realWebView; 567 | webView.delegate = nil; 568 | } 569 | else { 570 | WKWebView* webView = _realWebView; 571 | webView.UIDelegate = nil; 572 | webView.navigationDelegate = nil; 573 | 574 | [webView removeObserver:self forKeyPath:@"estimatedProgress"]; 575 | [webView removeObserver:self forKeyPath:@"title"]; 576 | } 577 | [_realWebView removeObserver:self forKeyPath:@"loading"]; 578 | [_realWebView scrollView].delegate = nil; 579 | [_realWebView stopLoading]; 580 | [(UIWebView*)_realWebView loadHTMLString:@"" baseURL:nil]; 581 | [_realWebView stopLoading]; 582 | [_realWebView removeFromSuperview]; 583 | _realWebView = nil; 584 | } 585 | @end 586 | -------------------------------------------------------------------------------- /Classes/UIWebViewProgress/IMY_NJKWebViewProgress.h: -------------------------------------------------------------------------------- 1 | // 2 | // IMY_NJKWebViewProgress.h 3 | // 4 | // Created by Satoshi Aasano on 4/20/13. 5 | // Copyright (c) 2013 Satoshi Asano. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | #undef IMY_NJK_weak 11 | #if __has_feature(objc_arc_weak) 12 | #define IMY_NJK_weak weak 13 | #else 14 | #define IMY_NJK_weak unsafe_unretained 15 | #endif 16 | 17 | typedef void (^IMY_NJKWebViewProgressBlock)(CGFloat progress); 18 | 19 | @protocol IMY_NJKWebViewProgressDelegate; 20 | @interface IMY_NJKWebViewProgress : NSObject 21 | 22 | @property (nonatomic, IMY_NJK_weak) id progressDelegate; 23 | @property (nonatomic, IMY_NJK_weak) id webViewProxyDelegate; 24 | @property (nonatomic, copy) IMY_NJKWebViewProgressBlock progressBlock; 25 | @property (nonatomic, readonly) CGFloat progress; // 0.0..1.0 26 | 27 | - (void)reset; 28 | 29 | @end 30 | 31 | @protocol IMY_NJKWebViewProgressDelegate 32 | - (void)webViewProgress:(IMY_NJKWebViewProgress *)webViewProgress updateProgress:(CGFloat)progress; 33 | @end 34 | 35 | -------------------------------------------------------------------------------- /Classes/UIWebViewProgress/IMY_NJKWebViewProgress.m: -------------------------------------------------------------------------------- 1 | // 2 | // IMY_NJKWebViewProgress.m 3 | // 4 | // Created by Satoshi Aasano on 4/20/13. 5 | // Copyright (c) 2013 Satoshi Asano. All rights reserved. 6 | // 7 | 8 | #import "IMY_NJKWebViewProgress.h" 9 | 10 | static NSString * const IMY_completeRPCURL = @"webviewprogressproxy:///complete"; 11 | 12 | const CGFloat IMY_NJKInitialProgressValue = 0.1; 13 | const CGFloat IMY_NJKInteractiveProgressValue = 0.5; 14 | const CGFloat IMY_NJKFinalProgressValue = 0.9; 15 | 16 | @implementation IMY_NJKWebViewProgress 17 | { 18 | NSUInteger _loadingCount; 19 | NSUInteger _maxLoadCount; 20 | NSURL *_currentURL; 21 | BOOL _interactive; 22 | } 23 | 24 | - (id)init 25 | { 26 | self = [super init]; 27 | if (self) { 28 | _maxLoadCount = _loadingCount = 0; 29 | _interactive = NO; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)startProgress 35 | { 36 | if (_progress < IMY_NJKInitialProgressValue) { 37 | [self setProgress:IMY_NJKInitialProgressValue]; 38 | } 39 | } 40 | 41 | - (void)incrementProgress 42 | { 43 | CGFloat progress = self.progress; 44 | CGFloat maxProgress = _interactive ? IMY_NJKFinalProgressValue : IMY_NJKInteractiveProgressValue; 45 | CGFloat remainPercent = (CGFloat)_loadingCount / (CGFloat)_maxLoadCount; 46 | CGFloat increment = (maxProgress - progress) * remainPercent; 47 | progress += increment; 48 | progress = fmin(progress, maxProgress); 49 | [self setProgress:progress]; 50 | } 51 | 52 | - (void)completeProgress 53 | { 54 | [self setProgress:1.0]; 55 | } 56 | 57 | - (void)setProgress:(CGFloat)progress 58 | { 59 | // progress should be incremental only 60 | if (progress > _progress || progress == 0) { 61 | _progress = progress; 62 | if ([_progressDelegate respondsToSelector:@selector(webViewProgress:updateProgress:)]) { 63 | [_progressDelegate webViewProgress:self updateProgress:progress]; 64 | } 65 | if (_progressBlock) { 66 | _progressBlock(progress); 67 | } 68 | } 69 | } 70 | 71 | - (void)reset 72 | { 73 | _maxLoadCount = _loadingCount = 0; 74 | _interactive = NO; 75 | [self setProgress:0.0]; 76 | } 77 | 78 | - (NSString *)getNonFragmentStringWithURL:(NSURL*)url 79 | { 80 | if (!url) { 81 | return @""; 82 | } 83 | if (url.fragment) { 84 | return [url.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:url.fragment] withString:@""]; 85 | } 86 | else { 87 | return url.absoluteString; 88 | } 89 | } 90 | 91 | #pragma mark - 92 | #pragma mark UIWebViewDelegate 93 | 94 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 95 | { 96 | if ([request.URL.absoluteString isEqualToString:IMY_completeRPCURL]) { 97 | [self completeProgress]; 98 | return NO; 99 | } 100 | 101 | BOOL ret = YES; 102 | if ([_webViewProxyDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) { 103 | ret = [_webViewProxyDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType]; 104 | } 105 | 106 | BOOL isFragmentJump = NO; 107 | if (request.URL.fragment) { 108 | NSString *nonFragmentURL = [self getNonFragmentStringWithURL:request.URL]; 109 | NSString *mainFragmentURL = [self getNonFragmentStringWithURL:webView.request.URL]; 110 | isFragmentJump = [nonFragmentURL isEqualToString:mainFragmentURL]; 111 | } 112 | 113 | NSString* refererURL = [request valueForHTTPHeaderField:@"Referer"]; 114 | BOOL isTopLevelNavigation = (refererURL.length == 0 || [refererURL isEqualToString:request.URL.absoluteString] || [request.mainDocumentURL isEqual:request.URL]); 115 | 116 | BOOL isHTTP = [request.URL.scheme isEqualToString:@"http"] || [request.URL.scheme isEqualToString:@"https"]; 117 | BOOL shouldReset = ret && !isFragmentJump && isHTTP && isTopLevelNavigation; 118 | shouldReset |= (navigationType == UIWebViewNavigationTypeReload); 119 | if (shouldReset) { 120 | _currentURL = request.URL; 121 | [self reset]; 122 | } 123 | return ret; 124 | } 125 | 126 | - (void)webViewDidStartLoad:(UIWebView *)webView 127 | { 128 | if ([_webViewProxyDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) { 129 | [_webViewProxyDelegate webViewDidStartLoad:webView]; 130 | } 131 | 132 | _loadingCount++; 133 | _maxLoadCount = fmax(_maxLoadCount, _loadingCount); 134 | 135 | [self startProgress]; 136 | } 137 | 138 | - (void)webViewDidFinishLoad:(UIWebView *)webView 139 | { 140 | if ([_webViewProxyDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) { 141 | [_webViewProxyDelegate webViewDidFinishLoad:webView]; 142 | } 143 | 144 | _loadingCount--; 145 | [self incrementProgress]; 146 | 147 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; 148 | 149 | BOOL interactive = [readyState isEqualToString:@"interactive"]; 150 | if (interactive) { 151 | _interactive = YES; 152 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe); }, false);", IMY_completeRPCURL]; 153 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS]; 154 | } 155 | 156 | BOOL isNotRedirect = YES; 157 | { 158 | NSString *nonFragmentCurrentURL = [self getNonFragmentStringWithURL:_currentURL]; 159 | NSString *nonFragmentMainDocumentURL = [self getNonFragmentStringWithURL:webView.request.mainDocumentURL]; 160 | isNotRedirect = (_currentURL && [nonFragmentCurrentURL isEqualToString:nonFragmentMainDocumentURL]); 161 | } 162 | BOOL complete = [readyState isEqualToString:@"complete"]; 163 | if (complete && isNotRedirect) { 164 | [self completeProgress]; 165 | } 166 | } 167 | 168 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 169 | { 170 | if ([_webViewProxyDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) { 171 | [_webViewProxyDelegate webView:webView didFailLoadWithError:error]; 172 | } 173 | 174 | _loadingCount--; 175 | [self incrementProgress]; 176 | 177 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"]; 178 | 179 | BOOL interactive = [readyState isEqualToString:@"interactive"]; 180 | if (interactive) { 181 | _interactive = YES; 182 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe); }, false);", IMY_completeRPCURL]; 183 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS]; 184 | } 185 | 186 | BOOL isNotRedirect = YES; 187 | { 188 | NSString *nonFragmentCurrentURL = [self getNonFragmentStringWithURL:_currentURL]; 189 | NSString *nonFragmentMainDocumentURL = [self getNonFragmentStringWithURL:webView.request.mainDocumentURL]; 190 | isNotRedirect = (_currentURL && [nonFragmentCurrentURL isEqualToString:nonFragmentMainDocumentURL]); 191 | } 192 | BOOL complete = [readyState isEqualToString:@"complete"]; 193 | if (complete && isNotRedirect) { 194 | [self completeProgress]; 195 | } 196 | } 197 | 198 | #pragma mark - 199 | #pragma mark Method Forwarding 200 | // for future UIWebViewDelegate impl 201 | 202 | - (BOOL)respondsToSelector:(SEL)aSelector 203 | { 204 | if ( [super respondsToSelector:aSelector] ) 205 | return YES; 206 | 207 | if ([self.webViewProxyDelegate respondsToSelector:aSelector]) 208 | return YES; 209 | 210 | return NO; 211 | } 212 | 213 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector 214 | { 215 | NSMethodSignature *signature = [super methodSignatureForSelector:selector]; 216 | if(!signature) { 217 | if([_webViewProxyDelegate respondsToSelector:selector]) { 218 | return [(NSObject *)_webViewProxyDelegate methodSignatureForSelector:selector]; 219 | } 220 | } 221 | return signature; 222 | } 223 | 224 | - (void)forwardInvocation:(NSInvocation*)invocation 225 | { 226 | if ([_webViewProxyDelegate respondsToSelector:[invocation selector]]) { 227 | [invocation invokeWithTarget:_webViewProxyDelegate]; 228 | } 229 | } 230 | 231 | @end 232 | -------------------------------------------------------------------------------- /IMYWebView.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "IMYWebView", 3 | "version": "0.6", 4 | "summary": "UIWebView seamless switching to WKWebView", 5 | "description": "UIWebView 无缝切换成 WKWebView 并支持查看UIWebView的显示进度", 6 | "homepage": "https://github.com/li6185377/IMYWebView", 7 | "license": "MIT", 8 | "authors": { 9 | "Jianghuai Li": "li6185377@163.com" 10 | }, 11 | "source": { 12 | "git": "https://github.com/li6185377/IMYWebView.git", 13 | "tag": "0.6" 14 | }, 15 | "platforms": { 16 | "ios": "5.0" 17 | }, 18 | "source_files": "Classes/**/*.{h,m}", 19 | "requires_arc": true, 20 | "weak_frameworks": [ 21 | "WebKit", 22 | "JavaScriptCore" 23 | ] 24 | } -------------------------------------------------------------------------------- /IMYWebView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3647126D1B7F2F19001C78B8 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3647126C1B7F2F19001C78B8 /* WebKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 11 | 366B23001CFD7CDE006743C0 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 366B22FF1CFD7CDE006743C0 /* JavaScriptCore.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 12 | 36A5AE2B1B4627E100DF4CD0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE2A1B4627E100DF4CD0 /* main.m */; }; 13 | 36A5AE2E1B4627E100DF4CD0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE2D1B4627E100DF4CD0 /* AppDelegate.m */; }; 14 | 36A5AE311B4627E100DF4CD0 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE301B4627E100DF4CD0 /* FirstViewController.m */; }; 15 | 36A5AE341B4627E100DF4CD0 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE331B4627E100DF4CD0 /* SecondViewController.m */; }; 16 | 36A5AE371B4627E100DF4CD0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36A5AE351B4627E100DF4CD0 /* Main.storyboard */; }; 17 | 36A5AE391B4627E100DF4CD0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36A5AE381B4627E100DF4CD0 /* Images.xcassets */; }; 18 | 36A5AE3C1B4627E100DF4CD0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 36A5AE3A1B4627E100DF4CD0 /* LaunchScreen.xib */; }; 19 | 36A5AE481B4627E100DF4CD0 /* IMYWebViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE471B4627E100DF4CD0 /* IMYWebViewTests.m */; }; 20 | 36A5AE6A1B46282F00DF4CD0 /* IMYWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE531B46282F00DF4CD0 /* IMYWebView.m */; }; 21 | 36A5AE711B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE701B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | 36A5AE421B4627E100DF4CD0 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = 36A5AE1D1B4627E100DF4CD0 /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = 36A5AE241B4627E100DF4CD0; 30 | remoteInfo = IMYWebView; 31 | }; 32 | /* End PBXContainerItemProxy section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | 3647126C1B7F2F19001C78B8 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 36 | 366B22FF1CFD7CDE006743C0 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 37 | 36A5AE251B4627E100DF4CD0 /* IMYWebView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IMYWebView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 36A5AE291B4627E100DF4CD0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | 36A5AE2A1B4627E100DF4CD0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 40 | 36A5AE2C1B4627E100DF4CD0 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 41 | 36A5AE2D1B4627E100DF4CD0 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 42 | 36A5AE2F1B4627E100DF4CD0 /* FirstViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = ""; }; 43 | 36A5AE301B4627E100DF4CD0 /* FirstViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = ""; }; 44 | 36A5AE321B4627E100DF4CD0 /* SecondViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; 45 | 36A5AE331B4627E100DF4CD0 /* SecondViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; 46 | 36A5AE361B4627E100DF4CD0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 47 | 36A5AE381B4627E100DF4CD0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 48 | 36A5AE3B1B4627E100DF4CD0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 49 | 36A5AE411B4627E100DF4CD0 /* IMYWebViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IMYWebViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 36A5AE461B4627E100DF4CD0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 36A5AE471B4627E100DF4CD0 /* IMYWebViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IMYWebViewTests.m; sourceTree = ""; }; 52 | 36A5AE521B46282F00DF4CD0 /* IMYWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IMYWebView.h; sourceTree = ""; }; 53 | 36A5AE531B46282F00DF4CD0 /* IMYWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IMYWebView.m; sourceTree = ""; }; 54 | 36A5AE6F1B462AE500DF4CD0 /* IMY_NJKWebViewProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IMY_NJKWebViewProgress.h; sourceTree = ""; }; 55 | 36A5AE701B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IMY_NJKWebViewProgress.m; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 36A5AE221B4627E100DF4CD0 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | 366B23001CFD7CDE006743C0 /* JavaScriptCore.framework in Frameworks */, 64 | 3647126D1B7F2F19001C78B8 /* WebKit.framework in Frameworks */, 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | 36A5AE3E1B4627E100DF4CD0 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | /* End PBXFrameworksBuildPhase section */ 76 | 77 | /* Begin PBXGroup section */ 78 | 36A5AE1C1B4627E100DF4CD0 = { 79 | isa = PBXGroup; 80 | children = ( 81 | 366B22FF1CFD7CDE006743C0 /* JavaScriptCore.framework */, 82 | 3647126C1B7F2F19001C78B8 /* WebKit.framework */, 83 | 36A5AE511B46282F00DF4CD0 /* Classes */, 84 | 36A5AE271B4627E100DF4CD0 /* IMYWebView */, 85 | 36A5AE441B4627E100DF4CD0 /* IMYWebViewTests */, 86 | 36A5AE261B4627E100DF4CD0 /* Products */, 87 | ); 88 | sourceTree = ""; 89 | }; 90 | 36A5AE261B4627E100DF4CD0 /* Products */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 36A5AE251B4627E100DF4CD0 /* IMYWebView.app */, 94 | 36A5AE411B4627E100DF4CD0 /* IMYWebViewTests.xctest */, 95 | ); 96 | name = Products; 97 | sourceTree = ""; 98 | }; 99 | 36A5AE271B4627E100DF4CD0 /* IMYWebView */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 36A5AE2C1B4627E100DF4CD0 /* AppDelegate.h */, 103 | 36A5AE2D1B4627E100DF4CD0 /* AppDelegate.m */, 104 | 36A5AE2F1B4627E100DF4CD0 /* FirstViewController.h */, 105 | 36A5AE301B4627E100DF4CD0 /* FirstViewController.m */, 106 | 36A5AE321B4627E100DF4CD0 /* SecondViewController.h */, 107 | 36A5AE331B4627E100DF4CD0 /* SecondViewController.m */, 108 | 36A5AE351B4627E100DF4CD0 /* Main.storyboard */, 109 | 36A5AE381B4627E100DF4CD0 /* Images.xcassets */, 110 | 36A5AE3A1B4627E100DF4CD0 /* LaunchScreen.xib */, 111 | 36A5AE281B4627E100DF4CD0 /* Supporting Files */, 112 | ); 113 | path = IMYWebView; 114 | sourceTree = ""; 115 | }; 116 | 36A5AE281B4627E100DF4CD0 /* Supporting Files */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 36A5AE291B4627E100DF4CD0 /* Info.plist */, 120 | 36A5AE2A1B4627E100DF4CD0 /* main.m */, 121 | ); 122 | name = "Supporting Files"; 123 | sourceTree = ""; 124 | }; 125 | 36A5AE441B4627E100DF4CD0 /* IMYWebViewTests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 36A5AE471B4627E100DF4CD0 /* IMYWebViewTests.m */, 129 | 36A5AE451B4627E100DF4CD0 /* Supporting Files */, 130 | ); 131 | path = IMYWebViewTests; 132 | sourceTree = ""; 133 | }; 134 | 36A5AE451B4627E100DF4CD0 /* Supporting Files */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 36A5AE461B4627E100DF4CD0 /* Info.plist */, 138 | ); 139 | name = "Supporting Files"; 140 | sourceTree = ""; 141 | }; 142 | 36A5AE511B46282F00DF4CD0 /* Classes */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 36A5AE521B46282F00DF4CD0 /* IMYWebView.h */, 146 | 36A5AE531B46282F00DF4CD0 /* IMYWebView.m */, 147 | 36A5AE6E1B462AE500DF4CD0 /* UIWebViewProgress */, 148 | ); 149 | path = Classes; 150 | sourceTree = ""; 151 | }; 152 | 36A5AE6E1B462AE500DF4CD0 /* UIWebViewProgress */ = { 153 | isa = PBXGroup; 154 | children = ( 155 | 36A5AE6F1B462AE500DF4CD0 /* IMY_NJKWebViewProgress.h */, 156 | 36A5AE701B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m */, 157 | ); 158 | path = UIWebViewProgress; 159 | sourceTree = ""; 160 | }; 161 | /* End PBXGroup section */ 162 | 163 | /* Begin PBXNativeTarget section */ 164 | 36A5AE241B4627E100DF4CD0 /* IMYWebView */ = { 165 | isa = PBXNativeTarget; 166 | buildConfigurationList = 36A5AE4B1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebView" */; 167 | buildPhases = ( 168 | 36A5AE211B4627E100DF4CD0 /* Sources */, 169 | 36A5AE221B4627E100DF4CD0 /* Frameworks */, 170 | 36A5AE231B4627E100DF4CD0 /* Resources */, 171 | ); 172 | buildRules = ( 173 | ); 174 | dependencies = ( 175 | ); 176 | name = IMYWebView; 177 | productName = IMYWebView; 178 | productReference = 36A5AE251B4627E100DF4CD0 /* IMYWebView.app */; 179 | productType = "com.apple.product-type.application"; 180 | }; 181 | 36A5AE401B4627E100DF4CD0 /* IMYWebViewTests */ = { 182 | isa = PBXNativeTarget; 183 | buildConfigurationList = 36A5AE4E1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebViewTests" */; 184 | buildPhases = ( 185 | 36A5AE3D1B4627E100DF4CD0 /* Sources */, 186 | 36A5AE3E1B4627E100DF4CD0 /* Frameworks */, 187 | 36A5AE3F1B4627E100DF4CD0 /* Resources */, 188 | ); 189 | buildRules = ( 190 | ); 191 | dependencies = ( 192 | 36A5AE431B4627E100DF4CD0 /* PBXTargetDependency */, 193 | ); 194 | name = IMYWebViewTests; 195 | productName = IMYWebViewTests; 196 | productReference = 36A5AE411B4627E100DF4CD0 /* IMYWebViewTests.xctest */; 197 | productType = "com.apple.product-type.bundle.unit-test"; 198 | }; 199 | /* End PBXNativeTarget section */ 200 | 201 | /* Begin PBXProject section */ 202 | 36A5AE1D1B4627E100DF4CD0 /* Project object */ = { 203 | isa = PBXProject; 204 | attributes = { 205 | LastUpgradeCheck = 0630; 206 | ORGANIZATIONNAME = IMY; 207 | TargetAttributes = { 208 | 36A5AE241B4627E100DF4CD0 = { 209 | CreatedOnToolsVersion = 6.3; 210 | }; 211 | 36A5AE401B4627E100DF4CD0 = { 212 | CreatedOnToolsVersion = 6.3; 213 | TestTargetID = 36A5AE241B4627E100DF4CD0; 214 | }; 215 | }; 216 | }; 217 | buildConfigurationList = 36A5AE201B4627E100DF4CD0 /* Build configuration list for PBXProject "IMYWebView" */; 218 | compatibilityVersion = "Xcode 3.2"; 219 | developmentRegion = English; 220 | hasScannedForEncodings = 0; 221 | knownRegions = ( 222 | en, 223 | Base, 224 | ); 225 | mainGroup = 36A5AE1C1B4627E100DF4CD0; 226 | productRefGroup = 36A5AE261B4627E100DF4CD0 /* Products */; 227 | projectDirPath = ""; 228 | projectRoot = ""; 229 | targets = ( 230 | 36A5AE241B4627E100DF4CD0 /* IMYWebView */, 231 | 36A5AE401B4627E100DF4CD0 /* IMYWebViewTests */, 232 | ); 233 | }; 234 | /* End PBXProject section */ 235 | 236 | /* Begin PBXResourcesBuildPhase section */ 237 | 36A5AE231B4627E100DF4CD0 /* Resources */ = { 238 | isa = PBXResourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | 36A5AE371B4627E100DF4CD0 /* Main.storyboard in Resources */, 242 | 36A5AE3C1B4627E100DF4CD0 /* LaunchScreen.xib in Resources */, 243 | 36A5AE391B4627E100DF4CD0 /* Images.xcassets in Resources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | 36A5AE3F1B4627E100DF4CD0 /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | /* End PBXResourcesBuildPhase section */ 255 | 256 | /* Begin PBXSourcesBuildPhase section */ 257 | 36A5AE211B4627E100DF4CD0 /* Sources */ = { 258 | isa = PBXSourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 36A5AE711B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m in Sources */, 262 | 36A5AE341B4627E100DF4CD0 /* SecondViewController.m in Sources */, 263 | 36A5AE2E1B4627E100DF4CD0 /* AppDelegate.m in Sources */, 264 | 36A5AE311B4627E100DF4CD0 /* FirstViewController.m in Sources */, 265 | 36A5AE6A1B46282F00DF4CD0 /* IMYWebView.m in Sources */, 266 | 36A5AE2B1B4627E100DF4CD0 /* main.m in Sources */, 267 | ); 268 | runOnlyForDeploymentPostprocessing = 0; 269 | }; 270 | 36A5AE3D1B4627E100DF4CD0 /* Sources */ = { 271 | isa = PBXSourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | 36A5AE481B4627E100DF4CD0 /* IMYWebViewTests.m in Sources */, 275 | ); 276 | runOnlyForDeploymentPostprocessing = 0; 277 | }; 278 | /* End PBXSourcesBuildPhase section */ 279 | 280 | /* Begin PBXTargetDependency section */ 281 | 36A5AE431B4627E100DF4CD0 /* PBXTargetDependency */ = { 282 | isa = PBXTargetDependency; 283 | target = 36A5AE241B4627E100DF4CD0 /* IMYWebView */; 284 | targetProxy = 36A5AE421B4627E100DF4CD0 /* PBXContainerItemProxy */; 285 | }; 286 | /* End PBXTargetDependency section */ 287 | 288 | /* Begin PBXVariantGroup section */ 289 | 36A5AE351B4627E100DF4CD0 /* Main.storyboard */ = { 290 | isa = PBXVariantGroup; 291 | children = ( 292 | 36A5AE361B4627E100DF4CD0 /* Base */, 293 | ); 294 | name = Main.storyboard; 295 | sourceTree = ""; 296 | }; 297 | 36A5AE3A1B4627E100DF4CD0 /* LaunchScreen.xib */ = { 298 | isa = PBXVariantGroup; 299 | children = ( 300 | 36A5AE3B1B4627E100DF4CD0 /* Base */, 301 | ); 302 | name = LaunchScreen.xib; 303 | sourceTree = ""; 304 | }; 305 | /* End PBXVariantGroup section */ 306 | 307 | /* Begin XCBuildConfiguration section */ 308 | 36A5AE491B4627E100DF4CD0 /* Debug */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ALWAYS_SEARCH_USER_PATHS = NO; 312 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 313 | CLANG_CXX_LIBRARY = "libc++"; 314 | CLANG_ENABLE_MODULES = YES; 315 | CLANG_ENABLE_OBJC_ARC = YES; 316 | CLANG_WARN_BOOL_CONVERSION = YES; 317 | CLANG_WARN_CONSTANT_CONVERSION = YES; 318 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 319 | CLANG_WARN_EMPTY_BODY = YES; 320 | CLANG_WARN_ENUM_CONVERSION = YES; 321 | CLANG_WARN_INT_CONVERSION = YES; 322 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 323 | CLANG_WARN_UNREACHABLE_CODE = YES; 324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 326 | COPY_PHASE_STRIP = NO; 327 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 328 | ENABLE_STRICT_OBJC_MSGSEND = YES; 329 | GCC_C_LANGUAGE_STANDARD = gnu99; 330 | GCC_DYNAMIC_NO_PIC = NO; 331 | GCC_NO_COMMON_BLOCKS = YES; 332 | GCC_OPTIMIZATION_LEVEL = 0; 333 | GCC_PREPROCESSOR_DEFINITIONS = ( 334 | "DEBUG=1", 335 | "$(inherited)", 336 | ); 337 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 338 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 339 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 340 | GCC_WARN_UNDECLARED_SELECTOR = YES; 341 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 342 | GCC_WARN_UNUSED_FUNCTION = YES; 343 | GCC_WARN_UNUSED_VARIABLE = YES; 344 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 345 | MTL_ENABLE_DEBUG_INFO = YES; 346 | ONLY_ACTIVE_ARCH = YES; 347 | SDKROOT = iphoneos; 348 | }; 349 | name = Debug; 350 | }; 351 | 36A5AE4A1B4627E100DF4CD0 /* Release */ = { 352 | isa = XCBuildConfiguration; 353 | buildSettings = { 354 | ALWAYS_SEARCH_USER_PATHS = NO; 355 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 356 | CLANG_CXX_LIBRARY = "libc++"; 357 | CLANG_ENABLE_MODULES = YES; 358 | CLANG_ENABLE_OBJC_ARC = YES; 359 | CLANG_WARN_BOOL_CONVERSION = YES; 360 | CLANG_WARN_CONSTANT_CONVERSION = YES; 361 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 362 | CLANG_WARN_EMPTY_BODY = YES; 363 | CLANG_WARN_ENUM_CONVERSION = YES; 364 | CLANG_WARN_INT_CONVERSION = YES; 365 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 366 | CLANG_WARN_UNREACHABLE_CODE = YES; 367 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 368 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 369 | COPY_PHASE_STRIP = NO; 370 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 371 | ENABLE_NS_ASSERTIONS = NO; 372 | ENABLE_STRICT_OBJC_MSGSEND = YES; 373 | GCC_C_LANGUAGE_STANDARD = gnu99; 374 | GCC_NO_COMMON_BLOCKS = YES; 375 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 376 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 377 | GCC_WARN_UNDECLARED_SELECTOR = YES; 378 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 379 | GCC_WARN_UNUSED_FUNCTION = YES; 380 | GCC_WARN_UNUSED_VARIABLE = YES; 381 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 382 | MTL_ENABLE_DEBUG_INFO = NO; 383 | SDKROOT = iphoneos; 384 | VALIDATE_PRODUCT = YES; 385 | }; 386 | name = Release; 387 | }; 388 | 36A5AE4C1B4627E100DF4CD0 /* Debug */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 392 | INFOPLIST_FILE = IMYWebView/Info.plist; 393 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 394 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 395 | PRODUCT_NAME = "$(TARGET_NAME)"; 396 | }; 397 | name = Debug; 398 | }; 399 | 36A5AE4D1B4627E100DF4CD0 /* Release */ = { 400 | isa = XCBuildConfiguration; 401 | buildSettings = { 402 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 403 | INFOPLIST_FILE = IMYWebView/Info.plist; 404 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 405 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 406 | PRODUCT_NAME = "$(TARGET_NAME)"; 407 | }; 408 | name = Release; 409 | }; 410 | 36A5AE4F1B4627E100DF4CD0 /* Debug */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | BUNDLE_LOADER = "$(TEST_HOST)"; 414 | FRAMEWORK_SEARCH_PATHS = ( 415 | "$(SDKROOT)/Developer/Library/Frameworks", 416 | "$(inherited)", 417 | ); 418 | GCC_PREPROCESSOR_DEFINITIONS = ( 419 | "DEBUG=1", 420 | "$(inherited)", 421 | ); 422 | INFOPLIST_FILE = IMYWebViewTests/Info.plist; 423 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 424 | PRODUCT_NAME = "$(TARGET_NAME)"; 425 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IMYWebView.app/IMYWebView"; 426 | }; 427 | name = Debug; 428 | }; 429 | 36A5AE501B4627E100DF4CD0 /* Release */ = { 430 | isa = XCBuildConfiguration; 431 | buildSettings = { 432 | BUNDLE_LOADER = "$(TEST_HOST)"; 433 | FRAMEWORK_SEARCH_PATHS = ( 434 | "$(SDKROOT)/Developer/Library/Frameworks", 435 | "$(inherited)", 436 | ); 437 | INFOPLIST_FILE = IMYWebViewTests/Info.plist; 438 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IMYWebView.app/IMYWebView"; 441 | }; 442 | name = Release; 443 | }; 444 | /* End XCBuildConfiguration section */ 445 | 446 | /* Begin XCConfigurationList section */ 447 | 36A5AE201B4627E100DF4CD0 /* Build configuration list for PBXProject "IMYWebView" */ = { 448 | isa = XCConfigurationList; 449 | buildConfigurations = ( 450 | 36A5AE491B4627E100DF4CD0 /* Debug */, 451 | 36A5AE4A1B4627E100DF4CD0 /* Release */, 452 | ); 453 | defaultConfigurationIsVisible = 0; 454 | defaultConfigurationName = Release; 455 | }; 456 | 36A5AE4B1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebView" */ = { 457 | isa = XCConfigurationList; 458 | buildConfigurations = ( 459 | 36A5AE4C1B4627E100DF4CD0 /* Debug */, 460 | 36A5AE4D1B4627E100DF4CD0 /* Release */, 461 | ); 462 | defaultConfigurationIsVisible = 0; 463 | defaultConfigurationName = Release; 464 | }; 465 | 36A5AE4E1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebViewTests" */ = { 466 | isa = XCConfigurationList; 467 | buildConfigurations = ( 468 | 36A5AE4F1B4627E100DF4CD0 /* Debug */, 469 | 36A5AE501B4627E100DF4CD0 /* Release */, 470 | ); 471 | defaultConfigurationIsVisible = 0; 472 | defaultConfigurationName = Release; 473 | }; 474 | /* End XCConfigurationList section */ 475 | }; 476 | rootObject = 36A5AE1D1B4627E100DF4CD0 /* Project object */; 477 | } 478 | -------------------------------------------------------------------------------- /IMYWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /IMYWebView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /IMYWebView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "FirstViewController.h" 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @interface MYTabbarController : UITabBarController 16 | 17 | @end 18 | 19 | @implementation MYTabbarController 20 | -(void)viewDidLoad 21 | { 22 | [super viewDidLoad]; 23 | self.delegate = self; 24 | } 25 | -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 26 | { 27 | [[viewController valueForKey:@"webView"] reload]; 28 | } 29 | 30 | @end 31 | 32 | @implementation AppDelegate 33 | 34 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 35 | 36 | // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 37 | // [_window.rootViewController presentViewController:[FirstViewController new] animated:YES completion:nil]; 38 | // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 39 | // [_window.rootViewController dismissViewControllerAnimated:YES completion:nil]; 40 | // }); 41 | // }); 42 | return YES; 43 | } 44 | 45 | - (void)applicationWillResignActive:(UIApplication *)application { 46 | // 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. 47 | // 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. 48 | } 49 | 50 | - (void)applicationDidEnterBackground:(UIApplication *)application { 51 | // 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. 52 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 53 | } 54 | 55 | - (void)applicationWillEnterForeground:(UIApplication *)application { 56 | // 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. 57 | } 58 | 59 | - (void)applicationDidBecomeActive:(UIApplication *)application { 60 | // 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. 61 | } 62 | 63 | - (void)applicationWillTerminate:(UIApplication *)application { 64 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /IMYWebView/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /IMYWebView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /IMYWebView/FirstViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FirstViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /IMYWebView/FirstViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.m 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import "FirstViewController.h" 10 | #import "IMYWebView.h" 11 | 12 | @interface FirstViewController () 13 | @property(strong,nonatomic)IMYWebView* webView; 14 | @end 15 | 16 | @implementation FirstViewController 17 | -(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 18 | { 19 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 20 | if(self) 21 | { 22 | self.title = @"IMYWebView"; 23 | } 24 | return self; 25 | } 26 | - (void)viewDidLoad 27 | { 28 | self.view.backgroundColor = [UIColor whiteColor]; 29 | [super viewDidLoad]; 30 | self.webView = [[IMYWebView alloc] initWithFrame:self.view.bounds]; 31 | [self.view addSubview:_webView]; 32 | 33 | if(_webView.usingUIWebView) 34 | { 35 | self.title = @"ClickRefresh-UIWebView"; 36 | } 37 | else 38 | { 39 | self.title = @"ClickRefresh-WKWebView"; 40 | } 41 | 42 | [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.taobao.com"]]]; 43 | } 44 | 45 | - (void)didReceiveMemoryWarning { 46 | [super didReceiveMemoryWarning]; 47 | // Dispose of any resources that can be recreated. 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /IMYWebView/Images.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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /IMYWebView/Images.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "first.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /IMYWebView/Images.xcassets/first.imageset/first.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li6185377/IMYWebView/b453c4db6ef47d74d7e21280ace8bc4c1d4aa259/IMYWebView/Images.xcassets/first.imageset/first.pdf -------------------------------------------------------------------------------- /IMYWebView/Images.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "second.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /IMYWebView/Images.xcassets/second.imageset/second.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/li6185377/IMYWebView/b453c4db6ef47d74d7e21280ace8bc4c1d4aa259/IMYWebView/Images.xcassets/second.imageset/second.pdf -------------------------------------------------------------------------------- /IMYWebView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | IMY.$(PRODUCT_NAME:rfc1034identifier) 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 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UIStatusBarTintParameters 39 | 40 | UINavigationBar 41 | 42 | Style 43 | UIBarStyleDefault 44 | Translucent 45 | 46 | 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /IMYWebView/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /IMYWebView/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | #import "IMYWebView.h" 11 | @interface SecondViewController () 12 | @property(strong,nonatomic)IMYWebView* webView; 13 | @end 14 | 15 | @implementation SecondViewController 16 | -(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 17 | { 18 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 19 | if(self) 20 | { 21 | self.title = @"UIWebView"; 22 | } 23 | return self; 24 | } 25 | - (void)viewDidLoad 26 | { 27 | [super viewDidLoad]; 28 | 29 | self.webView = [[IMYWebView alloc] initWithFrame:self.view.bounds usingUIWebView:YES]; 30 | [self.view addSubview:_webView]; 31 | 32 | if(_webView.usingUIWebView) 33 | { 34 | self.title = @"ClickRefresh-UIWebView"; 35 | } 36 | else 37 | { 38 | self.title = @"ClickRefresh-WKWebView"; 39 | } 40 | 41 | [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.taobao.com"]]]; 42 | } 43 | 44 | - (void)didReceiveMemoryWarning { 45 | [super didReceiveMemoryWarning]; 46 | // Dispose of any resources that can be recreated. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /IMYWebView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // IMYWebView 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. 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 | -------------------------------------------------------------------------------- /IMYWebViewTests/IMYWebViewTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // IMYWebViewTests.m 3 | // IMYWebViewTests 4 | // 5 | // Created by ljh on 15/7/3. 6 | // Copyright (c) 2015年 IMY. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface IMYWebViewTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation IMYWebViewTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /IMYWebViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | IMY.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Jianghuai Li (https://github.com/li6185377) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IMYWebView 2 | UIWebView seamless switching to WKWebView
3 | 无缝切换 UIWebView 为 WKWebView 4 | 5 | ------------------------------------ 6 | 要求 7 | ==================================== 8 | 9 | * ARC only 10 | 11 | ##如何添加到项目中 12 | 13 | ```objective-c 14 | pod 'IMYWebView' 15 | ``` 16 | 17 | ##使用方法 18 | 19 | 直接把你项目中的 'UIWebView' 名称替换为 'IMYWebView' 20 | 21 | ##警告 22 | 部分在UIWebView显示正常的页面 在 WKWebView 会放大。 23 | 比如 taobao.com 的页面会放大 但是 tmall.com 就不会。。。。 24 | 难道是天猫做的更好????? 25 | --------------------------------------------------------------------------------