├── IMYWebView
├── Images.xcassets
│ ├── first.imageset
│ │ ├── first.pdf
│ │ └── Contents.json
│ ├── second.imageset
│ │ ├── second.pdf
│ │ └── Contents.json
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── FirstViewController.h
├── SecondViewController.h
├── AppDelegate.h
├── main.m
├── SecondViewController.m
├── FirstViewController.m
├── Info.plist
├── AppDelegate.m
└── Base.lproj
│ ├── LaunchScreen.xib
│ └── Main.storyboard
├── IMYWebView.xcodeproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── xinhua.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
├── xcuserdata
│ └── xinhua.xcuserdatad
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── IMYWebView.xcscheme
└── project.pbxproj
├── Classes
├── WYWeakScriptMessageDelegate.h
├── WYWeakScriptMessageDelegate.m
├── UIWebViewProgress
│ ├── IMY_NJKWebViewProgress.h
│ └── IMY_NJKWebViewProgress.m
├── IMYWebView.h
└── IMYWebView.m
├── IMYWebView.podspec.json
├── README.md
├── IMYWebViewTests
├── Info.plist
└── IMYWebViewTests.m
└── LICENSE
/IMYWebView/Images.xcassets/first.imageset/first.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangyangcc/IMYWebView/HEAD/IMYWebView/Images.xcassets/first.imageset/first.pdf
--------------------------------------------------------------------------------
/IMYWebView/Images.xcassets/second.imageset/second.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangyangcc/IMYWebView/HEAD/IMYWebView/Images.xcassets/second.imageset/second.pdf
--------------------------------------------------------------------------------
/IMYWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/IMYWebView.xcodeproj/project.xcworkspace/xcuserdata/xinhua.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wangyangcc/IMYWebView/HEAD/IMYWebView.xcodeproj/project.xcworkspace/xcuserdata/xinhua.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/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/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/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/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/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/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 |
--------------------------------------------------------------------------------
/Classes/WYWeakScriptMessageDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // WYWeakScriptMessageDelegate.h
3 | // IMYWebView
4 | //
5 | // Created by wangyangyang on 15/11/17.
6 | // Copyright © 2015年 IMY. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface WYWeakScriptMessageDelegate : NSObject
13 |
14 | @property (nonatomic, weak) id scriptDelegate;
15 |
16 | - (instancetype)initWithDelegate:(id)scriptDelegate;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/IMYWebView.podspec.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "IMYWebView",
3 | "version": "0.4",
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.4"
14 | },
15 | "platforms": {
16 | "ios": "5.0"
17 | },
18 | "source_files": ["Classes/*.{h,m}","Classes/*/*.{h,m}"],
19 | "requires_arc": true,
20 | "weak_frameworks": [
21 | "WebKit"
22 | ]
23 | }
--------------------------------------------------------------------------------
/IMYWebView.xcodeproj/xcuserdata/xinhua.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | IMYWebView.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 36A5AE241B4627E100DF4CD0
16 |
17 | primary
18 |
19 |
20 | 36A5AE401B4627E100DF4CD0
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IMYWebView
2 | UIWebView seamless switching to WKWebView
3 | 无缝切换 UIWebView 为 WKWebView
4 |
5 | ##要求
6 |
7 |
8 | * ARC only
9 |
10 | ##使用方法
11 |
12 | 直接把你项目中的 'UIWebView' 名称替换为 'IMYWebView'
13 |
14 | ##在原框架基础上,添加了`js回调oc`的相关方法,用法如下
15 | ```
16 | /**
17 | * iOS8下 本地注册js方法,让服务端调用
18 | */
19 | - (void)addJsMethodIniOS8
20 | {
21 | WYScriptMessageHandlerLeakAvoider *leakAvoider = [[WYScriptMessageHandlerLeakAvoider alloc] initWithDelegate:self];
22 | [_co_webView addScriptMessageHandler:leakAvoider name:@"closeMe"];
23 | }
24 | ```
25 | 在当前类`self`的`dealloc`里面调用下面的方法:
26 |
27 | ```
28 | /**
29 | * iOS8下 注销 本地注册的js方法
30 | */
31 | - (void)removeJsMethodIniOS8
32 | {
33 | [_co_webView removeScriptMessageHandlerForName:@"closeMe"];
34 | }
35 | ```
36 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/Classes/WYWeakScriptMessageDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // WYWeakScriptMessageDelegate.m
3 | // IMYWebView
4 | //
5 | // Created by wangyangyang on 15/11/17.
6 | // Copyright © 2015年 IMY. All rights reserved.
7 | //
8 |
9 | #import "WYWeakScriptMessageDelegate.h"
10 |
11 | @implementation WYWeakScriptMessageDelegate
12 |
13 | - (instancetype)initWithDelegate:(id)scriptDelegate
14 | {
15 | self = [super init];
16 | if (self) {
17 | _scriptDelegate = scriptDelegate;
18 | }
19 | return self;
20 | }
21 |
22 | #pragma mark - WKScriptMessageHandler
23 |
24 | - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
25 | {
26 | [self.scriptDelegate userContentController:userContentController didReceiveScriptMessage:message];
27 | }
28 |
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.
--------------------------------------------------------------------------------
/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 | extern const float IMY_NJKInitialProgressValue;
18 | extern const float IMY_NJKInteractiveProgressValue;
19 | extern const float IMY_NJKFinalProgressValue;
20 |
21 | typedef void (^IMY_NJKWebViewProgressBlock)(float progress);
22 | @protocol IMY_NJKWebViewProgressDelegate;
23 | @interface IMY_NJKWebViewProgress : NSObject
24 | @property (nonatomic, IMY_NJK_weak) idprogressDelegate;
25 | @property (nonatomic, IMY_NJK_weak) idwebViewProxyDelegate;
26 | @property (nonatomic, copy) IMY_NJKWebViewProgressBlock progressBlock;
27 | @property (nonatomic, readonly) float progress; // 0.0..1.0
28 |
29 | - (void)reset;
30 | @end
31 |
32 | @protocol IMY_NJKWebViewProgressDelegate
33 | - (void)webViewProgress:(IMY_NJKWebViewProgress *)webViewProgress updateProgress:(float)progress;
34 | @end
35 |
36 |
--------------------------------------------------------------------------------
/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.tmall.com"]]];
42 | }
43 |
44 | - (void)didReceiveMemoryWarning {
45 | [super didReceiveMemoryWarning];
46 | // Dispose of any resources that can be recreated.
47 | }
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/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.tmall.com"]]];
43 | }
44 |
45 | - (void)didReceiveMemoryWarning {
46 | [super didReceiveMemoryWarning];
47 | // Dispose of any resources that can be recreated.
48 | }
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/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 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | NSAppTransportSecurity
34 |
35 | NSAllowsArbitraryLoads
36 |
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 |
--------------------------------------------------------------------------------
/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 | #import
11 |
12 | @class IMYWebView;
13 | @protocol IMYWebViewDelegate
14 | @optional
15 |
16 | - (void)webViewDidStartLoad:(IMYWebView *)webView;
17 | - (void)webViewDidFinishLoad:(IMYWebView *)webView;
18 | - (void)webView:(IMYWebView *)webView didFailLoadWithError:(NSError *)error;
19 | - (BOOL)webView:(IMYWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
20 |
21 | @end
22 |
23 | ///无缝切换UIWebView 会根据系统版本自动选择 使用WKWebView 还是 UIWebView
24 | @interface IMYWebView : UIView
25 |
26 | ///使用UIWebView
27 | - (instancetype)initWithFrame:(CGRect)frame usingUIWebView:(BOOL)usingUIWebView;
28 |
29 | @property(weak,nonatomic)id delegate;
30 |
31 | ///内部使用的webView
32 | @property (nonatomic, readonly) id realWebView;
33 | ///是否正在使用 UIWebView
34 | @property (nonatomic, readonly) BOOL usingUIWebView;
35 | ///预估网页加载进度
36 | @property (nonatomic, readonly) double estimatedProgress;
37 |
38 | @property (nonatomic, readonly) NSURLRequest *originRequest;
39 |
40 | /**
41 | * 添加js回调oc通知方式,适用于 iOS8 之后
42 | */
43 | - (void)addScriptMessageHandler:(id )scriptMessageHandler name:(NSString *)name;
44 | /**
45 | * 注销 注册过的js回调oc通知方式,适用于 iOS8 之后
46 | */
47 | - (void)removeScriptMessageHandlerForName:(NSString *)name;
48 |
49 | ///back 层数
50 | - (NSInteger)countOfHistory;
51 | - (void)gobackWithStep:(NSInteger)step;
52 |
53 | ///---- UI 或者 WK 的API
54 | @property (nonatomic, readonly) UIScrollView *scrollView;
55 |
56 | - (id)loadRequest:(NSURLRequest *)request;
57 | - (id)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL;
58 |
59 | @property (nonatomic, readonly, copy) NSString *title;
60 | @property (nonatomic, readonly) NSURLRequest *currentRequest;
61 | @property (nonatomic, readonly) NSURL *URL;
62 |
63 | @property (nonatomic, readonly, getter=isLoading) BOOL loading;
64 | @property (nonatomic, readonly) BOOL canGoBack;
65 | @property (nonatomic, readonly) BOOL canGoForward;
66 |
67 | - (id)goBack;
68 | - (id)goForward;
69 | - (id)reload;
70 | - (id)reloadFromOrigin;
71 | - (void)stopLoading;
72 |
73 | - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler;
74 | ///不建议使用这个办法 因为会在内部等待webView 的执行结果
75 | - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)javaScriptString __deprecated_msg("Method deprecated. Use [evaluateJavaScript:completionHandler:]");
76 |
77 | ///是否根据视图大小来缩放页面 默认为YES
78 | @property (nonatomic) BOOL scalesPageToFit;
79 |
80 | @end
81 |
--------------------------------------------------------------------------------
/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.xcodeproj/xcuserdata/xinhua.xcuserdatad/xcschemes/IMYWebView.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/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 | NSString *completeRPCURL = @"webviewprogressproxy:///complete";
11 |
12 | const float IMY_NJKInitialProgressValue = 0.1f;
13 | const float IMY_NJKInteractiveProgressValue = 0.5f;
14 | const float IMY_NJKFinalProgressValue = 0.9f;
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 | float progress = self.progress;
44 | float maxProgress = _interactive ? IMY_NJKFinalProgressValue : IMY_NJKInteractiveProgressValue;
45 | float remainPercent = (float)_loadingCount / (float)_maxLoadCount;
46 | float 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:(float)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 | #pragma mark -
79 | #pragma mark UIWebViewDelegate
80 |
81 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
82 | {
83 | if ([request.URL.absoluteString isEqualToString:completeRPCURL]) {
84 | [self completeProgress];
85 | return NO;
86 | }
87 |
88 | BOOL ret = YES;
89 | if ([_webViewProxyDelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) {
90 | ret = [_webViewProxyDelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
91 | }
92 |
93 | BOOL isFragmentJump = NO;
94 | if (request.URL.fragment) {
95 | NSString *nonFragmentURL = [request.URL.absoluteString stringByReplacingOccurrencesOfString:[@"#" stringByAppendingString:request.URL.fragment] withString:@""];
96 | isFragmentJump = [nonFragmentURL isEqualToString:webView.request.URL.absoluteString];
97 | }
98 |
99 | BOOL isTopLevelNavigation = [request.mainDocumentURL isEqual:request.URL];
100 |
101 | BOOL isHTTP = [request.URL.scheme isEqualToString:@"http"] || [request.URL.scheme isEqualToString:@"https"];
102 | if (ret && !isFragmentJump && isHTTP && isTopLevelNavigation) {
103 | _currentURL = request.URL;
104 | [self reset];
105 | }
106 | return ret;
107 | }
108 |
109 | - (void)webViewDidStartLoad:(UIWebView *)webView
110 | {
111 | if ([_webViewProxyDelegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
112 | [_webViewProxyDelegate webViewDidStartLoad:webView];
113 | }
114 |
115 | _loadingCount++;
116 | _maxLoadCount = fmax(_maxLoadCount, _loadingCount);
117 |
118 | [self startProgress];
119 | }
120 |
121 | - (void)webViewDidFinishLoad:(UIWebView *)webView
122 | {
123 | if ([_webViewProxyDelegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
124 | [_webViewProxyDelegate webViewDidFinishLoad:webView];
125 | }
126 |
127 | _loadingCount--;
128 | [self incrementProgress];
129 |
130 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
131 |
132 | BOOL interactive = [readyState isEqualToString:@"interactive"];
133 | if (interactive) {
134 | _interactive = YES;
135 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe); }, false);", completeRPCURL];
136 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
137 | }
138 |
139 | BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
140 | BOOL complete = [readyState isEqualToString:@"complete"];
141 | if (complete && isNotRedirect) {
142 | [self completeProgress];
143 | }
144 | }
145 |
146 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
147 | {
148 | if ([_webViewProxyDelegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
149 | [_webViewProxyDelegate webView:webView didFailLoadWithError:error];
150 | }
151 |
152 | _loadingCount--;
153 | [self incrementProgress];
154 |
155 | NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
156 |
157 | BOOL interactive = [readyState isEqualToString:@"interactive"];
158 | if (interactive) {
159 | _interactive = YES;
160 | NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe); }, false);", completeRPCURL];
161 | [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
162 | }
163 |
164 | BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
165 | BOOL complete = [readyState isEqualToString:@"complete"];
166 | if (complete && isNotRedirect) {
167 | [self completeProgress];
168 | }
169 | }
170 |
171 | #pragma mark -
172 | #pragma mark Method Forwarding
173 | // for future UIWebViewDelegate impl
174 |
175 | - (BOOL)respondsToSelector:(SEL)aSelector
176 | {
177 | if ( [super respondsToSelector:aSelector] )
178 | return YES;
179 |
180 | if ([self.webViewProxyDelegate respondsToSelector:aSelector])
181 | return YES;
182 |
183 | return NO;
184 | }
185 |
186 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
187 | {
188 | NSMethodSignature *signature = [super methodSignatureForSelector:selector];
189 | if(!signature) {
190 | if([_webViewProxyDelegate respondsToSelector:selector]) {
191 | return [(NSObject *)_webViewProxyDelegate methodSignatureForSelector:selector];
192 | }
193 | }
194 | return signature;
195 | }
196 |
197 | - (void)forwardInvocation:(NSInvocation*)invocation
198 | {
199 | if ([_webViewProxyDelegate respondsToSelector:[invocation selector]]) {
200 | [invocation invokeWithTarget:_webViewProxyDelegate];
201 | }
202 | }
203 |
204 | @end
205 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | {
54 | _usingUIWebView = usingUIWebView;
55 | [self _initMyself];
56 | }
57 | return self;
58 | }
59 | -(void)_initMyself
60 | {
61 | Class wkWebView = NSClassFromString(@"WKWebView");
62 | if(wkWebView && self.usingUIWebView == NO)
63 | {
64 | [self initWKWebView];
65 | _usingUIWebView = NO;
66 | }
67 | else
68 | {
69 | [self initUIWebView];
70 | _usingUIWebView = YES;
71 | }
72 | self.scalesPageToFit = YES;
73 |
74 | [self.realWebView setFrame:self.bounds];
75 | [self.realWebView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
76 | [self addSubview:self.realWebView];
77 | }
78 | -(void)initWKWebView
79 | {
80 | WKWebViewConfiguration* configuration = [[NSClassFromString(@"WKWebViewConfiguration") alloc] init];
81 | configuration.preferences = [NSClassFromString(@"WKPreferences") new];
82 | configuration.userContentController = [NSClassFromString(@"WKUserContentController") new];
83 |
84 | WKWebView* webView = [[NSClassFromString(@"WKWebView") alloc] initWithFrame:self.bounds configuration:configuration];
85 | webView.UIDelegate = self;
86 | webView.navigationDelegate = self;
87 |
88 | webView.backgroundColor = [UIColor clearColor];
89 | webView.opaque = NO;
90 |
91 | [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
92 | [webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil];
93 |
94 | _realWebView = webView;
95 | }
96 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
97 | {
98 | if([keyPath isEqualToString:@"estimatedProgress"])
99 | {
100 | self.estimatedProgress = [change[NSKeyValueChangeNewKey] doubleValue];
101 | }
102 | else if([keyPath isEqualToString:@"title"])
103 | {
104 | self.title = change[NSKeyValueChangeNewKey];
105 | }
106 | }
107 | -(void)initUIWebView
108 | {
109 | UIWebView* webView = [[UIWebView alloc] initWithFrame:self.bounds];
110 | webView.backgroundColor = [UIColor clearColor];
111 | webView.opaque = NO;
112 | for (UIView *subview in [webView.scrollView subviews])
113 | {
114 | if ([subview isKindOfClass:[UIImageView class]])
115 | {
116 | ((UIImageView *) subview).image = nil;
117 | subview.backgroundColor = [UIColor clearColor];
118 | }
119 | }
120 |
121 | self.njkWebViewProgress = [[IMY_NJKWebViewProgress alloc] init];
122 | webView.delegate = _njkWebViewProgress;
123 | _njkWebViewProgress.webViewProxyDelegate = self;
124 | _njkWebViewProgress.progressDelegate = self;
125 |
126 | _realWebView = webView;
127 | }
128 |
129 | #pragma mark- UIWebViewDelegate
130 |
131 | - (void)webViewDidFinishLoad:(UIWebView *)webView
132 | {
133 | self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
134 | if(self.originRequest == nil)
135 | {
136 | self.originRequest = webView.request;
137 | }
138 |
139 | [self callback_webViewDidFinishLoad];
140 | }
141 | - (void)webViewDidStartLoad:(UIWebView *)webView
142 | {
143 | [self callback_webViewDidStartLoad];
144 | }
145 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
146 | {
147 | [self callback_webViewDidFailLoadWithError:error];
148 | }
149 | -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
150 | {
151 | BOOL resultBOOL = [self callback_webViewShouldStartLoadWithRequest:request navigationType:navigationType];
152 | return resultBOOL;
153 | }
154 | - (void)webViewProgress:(IMY_NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
155 | {
156 | self.estimatedProgress = progress;
157 | }
158 |
159 | #pragma mark- WKNavigationDelegate
160 | -(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
161 | {
162 | BOOL resultBOOL = [self callback_webViewShouldStartLoadWithRequest:navigationAction.request navigationType:navigationAction.navigationType];
163 | if(resultBOOL)
164 | {
165 | self.currentRequest = navigationAction.request;
166 | if(navigationAction.targetFrame == nil)
167 | {
168 | [webView loadRequest:navigationAction.request];
169 | }
170 | decisionHandler(WKNavigationActionPolicyAllow);
171 | }
172 | else
173 | {
174 | decisionHandler(WKNavigationActionPolicyCancel);
175 | }
176 | }
177 | -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
178 | {
179 | [self callback_webViewDidStartLoad];
180 | }
181 | -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
182 | {
183 | [self callback_webViewDidFinishLoad];
184 | }
185 | - (void)webView:(WKWebView *) webView didFailProvisionalNavigation: (WKNavigation *) navigation withError: (NSError *) error
186 | {
187 | [self callback_webViewDidFailLoadWithError:error];
188 | }
189 | - (void)webView: (WKWebView *)webView didFailNavigation:(WKNavigation *) navigation withError: (NSError *) error
190 | {
191 | [self callback_webViewDidFailLoadWithError:error];
192 | }
193 | #pragma mark- WKUIDelegate
194 | ///-- 还没用到
195 | #pragma mark- CALLBACK IMYVKWebView Delegate
196 |
197 | - (void)callback_webViewDidFinishLoad
198 | {
199 | if([self.delegate respondsToSelector:@selector(webViewDidFinishLoad:)])
200 | {
201 | [self.delegate webViewDidFinishLoad:self];
202 | }
203 | }
204 | - (void)callback_webViewDidStartLoad
205 | {
206 | if([self.delegate respondsToSelector:@selector(webViewDidStartLoad:)])
207 | {
208 | [self.delegate webViewDidStartLoad:self];
209 | }
210 | }
211 | - (void)callback_webViewDidFailLoadWithError:(NSError *)error
212 | {
213 | if([self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)])
214 | {
215 | [self.delegate webView:self didFailLoadWithError:error];
216 | }
217 | }
218 | -(BOOL)callback_webViewShouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(NSInteger)navigationType
219 | {
220 | BOOL resultBOOL = YES;
221 | if([self.delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)])
222 | {
223 | if(navigationType == -1) {
224 | navigationType = UIWebViewNavigationTypeOther;
225 | }
226 | resultBOOL = [self.delegate webView:self shouldStartLoadWithRequest:request navigationType:navigationType];
227 | }
228 | return resultBOOL;
229 | }
230 |
231 | #pragma mark- 基础方法
232 | -(UIScrollView *)scrollView
233 | {
234 | return [(id)self.realWebView scrollView];
235 | }
236 |
237 | - (id)loadRequest:(NSURLRequest *)request
238 | {
239 | self.originRequest = request;
240 | self.currentRequest = request;
241 |
242 | if(_usingUIWebView)
243 | {
244 | [(UIWebView*)self.realWebView loadRequest:request];
245 | return nil;
246 | }
247 | else
248 | {
249 | return [(WKWebView*)self.realWebView loadRequest:request];
250 | }
251 | }
252 | - (id)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
253 | {
254 | if(_usingUIWebView)
255 | {
256 | [(UIWebView*)self.realWebView loadHTMLString:string baseURL:baseURL];
257 | return nil;
258 | }
259 | else
260 | {
261 | return [(WKWebView*)self.realWebView loadHTMLString:string baseURL:baseURL];
262 | }
263 | }
264 | -(NSURLRequest *)currentRequest
265 | {
266 | if(_usingUIWebView)
267 | {
268 | return [(UIWebView*)self.realWebView request];;
269 | }
270 | else
271 | {
272 | return _currentRequest;
273 | }
274 | }
275 | -(NSURL *)URL
276 | {
277 | if(_usingUIWebView)
278 | {
279 | return [(UIWebView*)self.realWebView request].URL;;
280 | }
281 | else
282 | {
283 | return [(WKWebView*)self.realWebView URL];
284 | }
285 | }
286 | -(BOOL)isLoading
287 | {
288 | return [self.realWebView isLoading];
289 | }
290 | -(BOOL)canGoBack
291 | {
292 | return [self.realWebView canGoBack];
293 | }
294 | -(BOOL)canGoForward
295 | {
296 | return [self.realWebView canGoForward];
297 | }
298 |
299 | - (id)goBack
300 | {
301 | if(_usingUIWebView)
302 | {
303 | [(UIWebView*)self.realWebView goBack];
304 | return nil;
305 | }
306 | else
307 | {
308 | return [(WKWebView*)self.realWebView goBack];
309 | }
310 | }
311 | - (id)goForward
312 | {
313 | if(_usingUIWebView)
314 | {
315 | [(UIWebView*)self.realWebView goForward];
316 | return nil;
317 | }
318 | else
319 | {
320 | return [(WKWebView*)self.realWebView goForward];
321 | }
322 | }
323 | - (id)reload
324 | {
325 | if(_usingUIWebView)
326 | {
327 | [(UIWebView*)self.realWebView reload];
328 | return nil;
329 | }
330 | else
331 | {
332 | return [(WKWebView*)self.realWebView reload];
333 | }
334 | }
335 | - (id)reloadFromOrigin
336 | {
337 | if(_usingUIWebView)
338 | {
339 | if(self.originRequest)
340 | {
341 | [self evaluateJavaScript:[NSString stringWithFormat:@"window.location.replace('%@')",self.originRequest.URL.absoluteString] completionHandler:nil];
342 | }
343 | return nil;
344 | }
345 | else
346 | {
347 | return [(WKWebView*)self.realWebView reloadFromOrigin];
348 | }
349 | }
350 | - (void)stopLoading
351 | {
352 | [self.realWebView stopLoading];
353 | }
354 |
355 | - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
356 | {
357 | if(_usingUIWebView)
358 | {
359 | NSString* result = [(UIWebView*)self.realWebView stringByEvaluatingJavaScriptFromString:javaScriptString];
360 | if(completionHandler)
361 | {
362 | completionHandler(result,nil);
363 | }
364 | }
365 | else
366 | {
367 | return [(WKWebView*)self.realWebView evaluateJavaScript:javaScriptString completionHandler:completionHandler];
368 | }
369 | }
370 | -(NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)javaScriptString
371 | {
372 | if(_usingUIWebView)
373 | {
374 | NSString* result = [(UIWebView*)self.realWebView stringByEvaluatingJavaScriptFromString:javaScriptString];
375 | return result;
376 | }
377 | else
378 | {
379 | __block NSString* result = nil;
380 | __block BOOL isExecuted = NO;
381 | [(WKWebView*)self.realWebView evaluateJavaScript:javaScriptString completionHandler:^(id obj, NSError *error) {
382 | result = obj;
383 | isExecuted = YES;
384 | }];
385 |
386 | while (isExecuted == NO) {
387 | [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
388 | }
389 | return result;
390 | }
391 | }
392 | -(void)setScalesPageToFit:(BOOL)scalesPageToFit
393 | {
394 | if(_usingUIWebView)
395 | {
396 | UIWebView* webView = _realWebView;
397 | webView.scalesPageToFit = scalesPageToFit;
398 | }
399 | else
400 | {
401 | if(_scalesPageToFit == scalesPageToFit)
402 | {
403 | return;
404 | }
405 |
406 | WKWebView* webView = _realWebView;
407 |
408 | NSString *jScript = @"var meta = document.createElement('meta'); \
409 | meta.name = 'viewport'; \
410 | meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; \
411 | var head = document.getElementsByTagName('head')[0];\
412 | head.appendChild(meta);";
413 |
414 | if(scalesPageToFit)
415 | {
416 | WKUserScript *wkUScript = [[NSClassFromString(@"WKUserScript") alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
417 | [webView.configuration.userContentController addUserScript:wkUScript];
418 | }
419 | else
420 | {
421 | NSMutableArray* array = [NSMutableArray arrayWithArray:webView.configuration.userContentController.userScripts];
422 | for (WKUserScript *wkUScript in array)
423 | {
424 | if([wkUScript.source isEqual:jScript])
425 | {
426 | [array removeObject:wkUScript];
427 | break;
428 | }
429 | }
430 | for (WKUserScript *wkUScript in array)
431 | {
432 | [webView.configuration.userContentController addUserScript:wkUScript];
433 | }
434 | }
435 | }
436 |
437 | _scalesPageToFit = scalesPageToFit;
438 | }
439 | -(BOOL)scalesPageToFit
440 | {
441 | if(_usingUIWebView)
442 | {
443 | return [_realWebView scalesPageToFit];
444 | }
445 | else
446 | {
447 | return _scalesPageToFit;
448 | }
449 | }
450 |
451 | /**
452 | * 添加js回调oc通知方式,适用于 iOS8 之后
453 | */
454 | - (void)addScriptMessageHandler:(id )scriptMessageHandler name:(NSString *)name
455 | {
456 | if ([_realWebView isKindOfClass:NSClassFromString(@"WKWebView")]) {
457 | [[(WKWebView *)_realWebView configuration].userContentController addScriptMessageHandler:scriptMessageHandler name:name];
458 | }
459 | }
460 |
461 | /**
462 | * 注销 注册过的js回调oc通知方式,适用于 iOS8 之后
463 | */
464 | - (void)removeScriptMessageHandlerForName:(NSString *)name
465 | {
466 | if ([_realWebView isKindOfClass:NSClassFromString(@"WKWebView")]) {
467 | [[(WKWebView *)_realWebView configuration].userContentController removeScriptMessageHandlerForName:name];
468 | }
469 | }
470 |
471 | -(NSInteger)countOfHistory
472 | {
473 | if(_usingUIWebView)
474 | {
475 | UIWebView* webView = self.realWebView;
476 |
477 | int count = [[webView stringByEvaluatingJavaScriptFromString:@"window.history.length"] intValue];
478 | if (count)
479 | {
480 | return count;
481 | }
482 | else
483 | {
484 | return 1;
485 | }
486 | }
487 | else
488 | {
489 | WKWebView* webView = self.realWebView;
490 | return webView.backForwardList.backList.count;
491 | }
492 | }
493 | -(void)gobackWithStep:(NSInteger)step
494 | {
495 | if(self.canGoBack == NO)
496 | return;
497 |
498 | if(step > 0)
499 | {
500 | NSInteger historyCount = self.countOfHistory;
501 | if(step >= historyCount)
502 | {
503 | step = historyCount - 1;
504 | }
505 |
506 | if(_usingUIWebView)
507 | {
508 | UIWebView* webView = self.realWebView;
509 | [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.history.go(-%ld)", (long) step]];
510 | }
511 | else
512 | {
513 | WKWebView* webView = self.realWebView;
514 | WKBackForwardListItem* backItem = webView.backForwardList.backList[step];
515 | [webView goToBackForwardListItem:backItem];
516 | }
517 | }
518 | else
519 | {
520 | [self goBack];
521 | }
522 | }
523 | #pragma mark- 如果没有找到方法 去realWebView 中调用
524 | -(BOOL)respondsToSelector:(SEL)aSelector
525 | {
526 | BOOL hasResponds = [super respondsToSelector:aSelector];
527 | if(hasResponds == NO)
528 | {
529 | hasResponds = [self.delegate respondsToSelector:aSelector];
530 | }
531 | if(hasResponds == NO)
532 | {
533 | hasResponds = [self.realWebView respondsToSelector:aSelector];
534 | }
535 | return hasResponds;
536 | }
537 | - (NSMethodSignature*)methodSignatureForSelector:(SEL)selector
538 | {
539 | NSMethodSignature* methodSign = [super methodSignatureForSelector:selector];
540 | if(methodSign == nil)
541 | {
542 | if([self.realWebView respondsToSelector:selector])
543 | {
544 | methodSign = [self.realWebView methodSignatureForSelector:selector];
545 | }
546 | else
547 | {
548 | methodSign = [(id)self.delegate methodSignatureForSelector:selector];
549 | }
550 | }
551 | return methodSign;
552 | }
553 | - (void)forwardInvocation:(NSInvocation*)invocation
554 | {
555 | if([self.realWebView respondsToSelector:invocation.selector])
556 | {
557 | [invocation invokeWithTarget:self.realWebView];
558 | }
559 | else
560 | {
561 | [invocation invokeWithTarget:self.delegate];
562 | }
563 | }
564 |
565 | #pragma mark- 清理
566 | -(void)dealloc
567 | {
568 | if(_usingUIWebView)
569 | {
570 | UIWebView* webView = _realWebView;
571 | webView.delegate = nil;
572 | }
573 | else
574 | {
575 | WKWebView* webView = _realWebView;
576 | webView.UIDelegate = nil;
577 | webView.navigationDelegate = nil;
578 |
579 | [webView removeObserver:self forKeyPath:@"estimatedProgress"];
580 | [webView removeObserver:self forKeyPath:@"title"];
581 | }
582 | [_realWebView scrollView].delegate = nil;
583 | [_realWebView stopLoading];
584 | [(UIWebView*)_realWebView loadHTMLString:@"" baseURL:nil];
585 | [_realWebView stopLoading];
586 | [_realWebView removeFromSuperview];
587 | _realWebView = nil;
588 | }
589 | @end
590 |
--------------------------------------------------------------------------------
/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 */; };
11 | 36A5AE2B1B4627E100DF4CD0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE2A1B4627E100DF4CD0 /* main.m */; };
12 | 36A5AE2E1B4627E100DF4CD0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE2D1B4627E100DF4CD0 /* AppDelegate.m */; };
13 | 36A5AE311B4627E100DF4CD0 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE301B4627E100DF4CD0 /* FirstViewController.m */; };
14 | 36A5AE341B4627E100DF4CD0 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE331B4627E100DF4CD0 /* SecondViewController.m */; };
15 | 36A5AE371B4627E100DF4CD0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36A5AE351B4627E100DF4CD0 /* Main.storyboard */; };
16 | 36A5AE391B4627E100DF4CD0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36A5AE381B4627E100DF4CD0 /* Images.xcassets */; };
17 | 36A5AE3C1B4627E100DF4CD0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 36A5AE3A1B4627E100DF4CD0 /* LaunchScreen.xib */; };
18 | 36A5AE481B4627E100DF4CD0 /* IMYWebViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE471B4627E100DF4CD0 /* IMYWebViewTests.m */; };
19 | 36A5AE6A1B46282F00DF4CD0 /* IMYWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE531B46282F00DF4CD0 /* IMYWebView.m */; };
20 | 36A5AE711B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 36A5AE701B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m */; };
21 | E0B42D341BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E0B42D331BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.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 | 36A5AE251B4627E100DF4CD0 /* IMYWebView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IMYWebView.app; sourceTree = BUILT_PRODUCTS_DIR; };
37 | 36A5AE291B4627E100DF4CD0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
38 | 36A5AE2A1B4627E100DF4CD0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
39 | 36A5AE2C1B4627E100DF4CD0 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
40 | 36A5AE2D1B4627E100DF4CD0 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
41 | 36A5AE2F1B4627E100DF4CD0 /* FirstViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = ""; };
42 | 36A5AE301B4627E100DF4CD0 /* FirstViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = ""; };
43 | 36A5AE321B4627E100DF4CD0 /* SecondViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; };
44 | 36A5AE331B4627E100DF4CD0 /* SecondViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; };
45 | 36A5AE361B4627E100DF4CD0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
46 | 36A5AE381B4627E100DF4CD0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
47 | 36A5AE3B1B4627E100DF4CD0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
48 | 36A5AE411B4627E100DF4CD0 /* IMYWebViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IMYWebViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
49 | 36A5AE461B4627E100DF4CD0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
50 | 36A5AE471B4627E100DF4CD0 /* IMYWebViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IMYWebViewTests.m; sourceTree = ""; };
51 | 36A5AE521B46282F00DF4CD0 /* IMYWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IMYWebView.h; sourceTree = ""; };
52 | 36A5AE531B46282F00DF4CD0 /* IMYWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IMYWebView.m; sourceTree = ""; };
53 | 36A5AE6F1B462AE500DF4CD0 /* IMY_NJKWebViewProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IMY_NJKWebViewProgress.h; sourceTree = ""; };
54 | 36A5AE701B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IMY_NJKWebViewProgress.m; sourceTree = ""; };
55 | E0B42D321BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WYWeakScriptMessageDelegate.h; sourceTree = ""; };
56 | E0B42D331BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WYWeakScriptMessageDelegate.m; sourceTree = ""; };
57 | /* End PBXFileReference section */
58 |
59 | /* Begin PBXFrameworksBuildPhase section */
60 | 36A5AE221B4627E100DF4CD0 /* Frameworks */ = {
61 | isa = PBXFrameworksBuildPhase;
62 | buildActionMask = 2147483647;
63 | files = (
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 | 3647126C1B7F2F19001C78B8 /* WebKit.framework */,
82 | 36A5AE511B46282F00DF4CD0 /* Classes */,
83 | 36A5AE271B4627E100DF4CD0 /* IMYWebView */,
84 | 36A5AE441B4627E100DF4CD0 /* IMYWebViewTests */,
85 | 36A5AE261B4627E100DF4CD0 /* Products */,
86 | );
87 | sourceTree = "";
88 | };
89 | 36A5AE261B4627E100DF4CD0 /* Products */ = {
90 | isa = PBXGroup;
91 | children = (
92 | 36A5AE251B4627E100DF4CD0 /* IMYWebView.app */,
93 | 36A5AE411B4627E100DF4CD0 /* IMYWebViewTests.xctest */,
94 | );
95 | name = Products;
96 | sourceTree = "";
97 | };
98 | 36A5AE271B4627E100DF4CD0 /* IMYWebView */ = {
99 | isa = PBXGroup;
100 | children = (
101 | 36A5AE2C1B4627E100DF4CD0 /* AppDelegate.h */,
102 | 36A5AE2D1B4627E100DF4CD0 /* AppDelegate.m */,
103 | 36A5AE2F1B4627E100DF4CD0 /* FirstViewController.h */,
104 | 36A5AE301B4627E100DF4CD0 /* FirstViewController.m */,
105 | 36A5AE321B4627E100DF4CD0 /* SecondViewController.h */,
106 | 36A5AE331B4627E100DF4CD0 /* SecondViewController.m */,
107 | 36A5AE351B4627E100DF4CD0 /* Main.storyboard */,
108 | 36A5AE381B4627E100DF4CD0 /* Images.xcassets */,
109 | 36A5AE3A1B4627E100DF4CD0 /* LaunchScreen.xib */,
110 | 36A5AE281B4627E100DF4CD0 /* Supporting Files */,
111 | );
112 | path = IMYWebView;
113 | sourceTree = "";
114 | };
115 | 36A5AE281B4627E100DF4CD0 /* Supporting Files */ = {
116 | isa = PBXGroup;
117 | children = (
118 | 36A5AE291B4627E100DF4CD0 /* Info.plist */,
119 | 36A5AE2A1B4627E100DF4CD0 /* main.m */,
120 | );
121 | name = "Supporting Files";
122 | sourceTree = "";
123 | };
124 | 36A5AE441B4627E100DF4CD0 /* IMYWebViewTests */ = {
125 | isa = PBXGroup;
126 | children = (
127 | 36A5AE471B4627E100DF4CD0 /* IMYWebViewTests.m */,
128 | 36A5AE451B4627E100DF4CD0 /* Supporting Files */,
129 | );
130 | path = IMYWebViewTests;
131 | sourceTree = "";
132 | };
133 | 36A5AE451B4627E100DF4CD0 /* Supporting Files */ = {
134 | isa = PBXGroup;
135 | children = (
136 | 36A5AE461B4627E100DF4CD0 /* Info.plist */,
137 | );
138 | name = "Supporting Files";
139 | sourceTree = "";
140 | };
141 | 36A5AE511B46282F00DF4CD0 /* Classes */ = {
142 | isa = PBXGroup;
143 | children = (
144 | 36A5AE521B46282F00DF4CD0 /* IMYWebView.h */,
145 | 36A5AE531B46282F00DF4CD0 /* IMYWebView.m */,
146 | E0B42D321BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.h */,
147 | E0B42D331BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.m */,
148 | 36A5AE6E1B462AE500DF4CD0 /* UIWebViewProgress */,
149 | );
150 | path = Classes;
151 | sourceTree = "";
152 | };
153 | 36A5AE6E1B462AE500DF4CD0 /* UIWebViewProgress */ = {
154 | isa = PBXGroup;
155 | children = (
156 | 36A5AE6F1B462AE500DF4CD0 /* IMY_NJKWebViewProgress.h */,
157 | 36A5AE701B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m */,
158 | );
159 | path = UIWebViewProgress;
160 | sourceTree = "";
161 | };
162 | /* End PBXGroup section */
163 |
164 | /* Begin PBXNativeTarget section */
165 | 36A5AE241B4627E100DF4CD0 /* IMYWebView */ = {
166 | isa = PBXNativeTarget;
167 | buildConfigurationList = 36A5AE4B1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebView" */;
168 | buildPhases = (
169 | 36A5AE211B4627E100DF4CD0 /* Sources */,
170 | 36A5AE221B4627E100DF4CD0 /* Frameworks */,
171 | 36A5AE231B4627E100DF4CD0 /* Resources */,
172 | );
173 | buildRules = (
174 | );
175 | dependencies = (
176 | );
177 | name = IMYWebView;
178 | productName = IMYWebView;
179 | productReference = 36A5AE251B4627E100DF4CD0 /* IMYWebView.app */;
180 | productType = "com.apple.product-type.application";
181 | };
182 | 36A5AE401B4627E100DF4CD0 /* IMYWebViewTests */ = {
183 | isa = PBXNativeTarget;
184 | buildConfigurationList = 36A5AE4E1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebViewTests" */;
185 | buildPhases = (
186 | 36A5AE3D1B4627E100DF4CD0 /* Sources */,
187 | 36A5AE3E1B4627E100DF4CD0 /* Frameworks */,
188 | 36A5AE3F1B4627E100DF4CD0 /* Resources */,
189 | );
190 | buildRules = (
191 | );
192 | dependencies = (
193 | 36A5AE431B4627E100DF4CD0 /* PBXTargetDependency */,
194 | );
195 | name = IMYWebViewTests;
196 | productName = IMYWebViewTests;
197 | productReference = 36A5AE411B4627E100DF4CD0 /* IMYWebViewTests.xctest */;
198 | productType = "com.apple.product-type.bundle.unit-test";
199 | };
200 | /* End PBXNativeTarget section */
201 |
202 | /* Begin PBXProject section */
203 | 36A5AE1D1B4627E100DF4CD0 /* Project object */ = {
204 | isa = PBXProject;
205 | attributes = {
206 | LastUpgradeCheck = 0630;
207 | ORGANIZATIONNAME = IMY;
208 | TargetAttributes = {
209 | 36A5AE241B4627E100DF4CD0 = {
210 | CreatedOnToolsVersion = 6.3;
211 | };
212 | 36A5AE401B4627E100DF4CD0 = {
213 | CreatedOnToolsVersion = 6.3;
214 | TestTargetID = 36A5AE241B4627E100DF4CD0;
215 | };
216 | };
217 | };
218 | buildConfigurationList = 36A5AE201B4627E100DF4CD0 /* Build configuration list for PBXProject "IMYWebView" */;
219 | compatibilityVersion = "Xcode 3.2";
220 | developmentRegion = English;
221 | hasScannedForEncodings = 0;
222 | knownRegions = (
223 | en,
224 | Base,
225 | );
226 | mainGroup = 36A5AE1C1B4627E100DF4CD0;
227 | productRefGroup = 36A5AE261B4627E100DF4CD0 /* Products */;
228 | projectDirPath = "";
229 | projectRoot = "";
230 | targets = (
231 | 36A5AE241B4627E100DF4CD0 /* IMYWebView */,
232 | 36A5AE401B4627E100DF4CD0 /* IMYWebViewTests */,
233 | );
234 | };
235 | /* End PBXProject section */
236 |
237 | /* Begin PBXResourcesBuildPhase section */
238 | 36A5AE231B4627E100DF4CD0 /* Resources */ = {
239 | isa = PBXResourcesBuildPhase;
240 | buildActionMask = 2147483647;
241 | files = (
242 | 36A5AE371B4627E100DF4CD0 /* Main.storyboard in Resources */,
243 | 36A5AE3C1B4627E100DF4CD0 /* LaunchScreen.xib in Resources */,
244 | 36A5AE391B4627E100DF4CD0 /* Images.xcassets in Resources */,
245 | );
246 | runOnlyForDeploymentPostprocessing = 0;
247 | };
248 | 36A5AE3F1B4627E100DF4CD0 /* Resources */ = {
249 | isa = PBXResourcesBuildPhase;
250 | buildActionMask = 2147483647;
251 | files = (
252 | );
253 | runOnlyForDeploymentPostprocessing = 0;
254 | };
255 | /* End PBXResourcesBuildPhase section */
256 |
257 | /* Begin PBXSourcesBuildPhase section */
258 | 36A5AE211B4627E100DF4CD0 /* Sources */ = {
259 | isa = PBXSourcesBuildPhase;
260 | buildActionMask = 2147483647;
261 | files = (
262 | 36A5AE711B462AE500DF4CD0 /* IMY_NJKWebViewProgress.m in Sources */,
263 | 36A5AE341B4627E100DF4CD0 /* SecondViewController.m in Sources */,
264 | 36A5AE2E1B4627E100DF4CD0 /* AppDelegate.m in Sources */,
265 | 36A5AE311B4627E100DF4CD0 /* FirstViewController.m in Sources */,
266 | E0B42D341BFAC82D002F54C5 /* WYWeakScriptMessageDelegate.m in Sources */,
267 | 36A5AE6A1B46282F00DF4CD0 /* IMYWebView.m in Sources */,
268 | 36A5AE2B1B4627E100DF4CD0 /* main.m in Sources */,
269 | );
270 | runOnlyForDeploymentPostprocessing = 0;
271 | };
272 | 36A5AE3D1B4627E100DF4CD0 /* Sources */ = {
273 | isa = PBXSourcesBuildPhase;
274 | buildActionMask = 2147483647;
275 | files = (
276 | 36A5AE481B4627E100DF4CD0 /* IMYWebViewTests.m in Sources */,
277 | );
278 | runOnlyForDeploymentPostprocessing = 0;
279 | };
280 | /* End PBXSourcesBuildPhase section */
281 |
282 | /* Begin PBXTargetDependency section */
283 | 36A5AE431B4627E100DF4CD0 /* PBXTargetDependency */ = {
284 | isa = PBXTargetDependency;
285 | target = 36A5AE241B4627E100DF4CD0 /* IMYWebView */;
286 | targetProxy = 36A5AE421B4627E100DF4CD0 /* PBXContainerItemProxy */;
287 | };
288 | /* End PBXTargetDependency section */
289 |
290 | /* Begin PBXVariantGroup section */
291 | 36A5AE351B4627E100DF4CD0 /* Main.storyboard */ = {
292 | isa = PBXVariantGroup;
293 | children = (
294 | 36A5AE361B4627E100DF4CD0 /* Base */,
295 | );
296 | name = Main.storyboard;
297 | sourceTree = "";
298 | };
299 | 36A5AE3A1B4627E100DF4CD0 /* LaunchScreen.xib */ = {
300 | isa = PBXVariantGroup;
301 | children = (
302 | 36A5AE3B1B4627E100DF4CD0 /* Base */,
303 | );
304 | name = LaunchScreen.xib;
305 | sourceTree = "";
306 | };
307 | /* End PBXVariantGroup section */
308 |
309 | /* Begin XCBuildConfiguration section */
310 | 36A5AE491B4627E100DF4CD0 /* Debug */ = {
311 | isa = XCBuildConfiguration;
312 | buildSettings = {
313 | ALWAYS_SEARCH_USER_PATHS = NO;
314 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
315 | CLANG_CXX_LIBRARY = "libc++";
316 | CLANG_ENABLE_MODULES = YES;
317 | CLANG_ENABLE_OBJC_ARC = YES;
318 | CLANG_WARN_BOOL_CONVERSION = YES;
319 | CLANG_WARN_CONSTANT_CONVERSION = YES;
320 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
321 | CLANG_WARN_EMPTY_BODY = YES;
322 | CLANG_WARN_ENUM_CONVERSION = YES;
323 | CLANG_WARN_INT_CONVERSION = YES;
324 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
325 | CLANG_WARN_UNREACHABLE_CODE = YES;
326 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
327 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
328 | COPY_PHASE_STRIP = NO;
329 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
330 | ENABLE_STRICT_OBJC_MSGSEND = YES;
331 | GCC_C_LANGUAGE_STANDARD = gnu99;
332 | GCC_DYNAMIC_NO_PIC = NO;
333 | GCC_NO_COMMON_BLOCKS = YES;
334 | GCC_OPTIMIZATION_LEVEL = 0;
335 | GCC_PREPROCESSOR_DEFINITIONS = (
336 | "DEBUG=1",
337 | "$(inherited)",
338 | );
339 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
340 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
341 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
342 | GCC_WARN_UNDECLARED_SELECTOR = YES;
343 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
344 | GCC_WARN_UNUSED_FUNCTION = YES;
345 | GCC_WARN_UNUSED_VARIABLE = YES;
346 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
347 | MTL_ENABLE_DEBUG_INFO = YES;
348 | ONLY_ACTIVE_ARCH = YES;
349 | SDKROOT = iphoneos;
350 | };
351 | name = Debug;
352 | };
353 | 36A5AE4A1B4627E100DF4CD0 /* Release */ = {
354 | isa = XCBuildConfiguration;
355 | buildSettings = {
356 | ALWAYS_SEARCH_USER_PATHS = NO;
357 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
358 | CLANG_CXX_LIBRARY = "libc++";
359 | CLANG_ENABLE_MODULES = YES;
360 | CLANG_ENABLE_OBJC_ARC = YES;
361 | CLANG_WARN_BOOL_CONVERSION = YES;
362 | CLANG_WARN_CONSTANT_CONVERSION = YES;
363 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
364 | CLANG_WARN_EMPTY_BODY = YES;
365 | CLANG_WARN_ENUM_CONVERSION = YES;
366 | CLANG_WARN_INT_CONVERSION = YES;
367 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
368 | CLANG_WARN_UNREACHABLE_CODE = YES;
369 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
370 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
371 | COPY_PHASE_STRIP = NO;
372 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
373 | ENABLE_NS_ASSERTIONS = NO;
374 | ENABLE_STRICT_OBJC_MSGSEND = YES;
375 | GCC_C_LANGUAGE_STANDARD = gnu99;
376 | GCC_NO_COMMON_BLOCKS = YES;
377 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
378 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
379 | GCC_WARN_UNDECLARED_SELECTOR = YES;
380 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
381 | GCC_WARN_UNUSED_FUNCTION = YES;
382 | GCC_WARN_UNUSED_VARIABLE = YES;
383 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
384 | MTL_ENABLE_DEBUG_INFO = NO;
385 | SDKROOT = iphoneos;
386 | VALIDATE_PRODUCT = YES;
387 | };
388 | name = Release;
389 | };
390 | 36A5AE4C1B4627E100DF4CD0 /* Debug */ = {
391 | isa = XCBuildConfiguration;
392 | buildSettings = {
393 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
394 | INFOPLIST_FILE = IMYWebView/Info.plist;
395 | IPHONEOS_DEPLOYMENT_TARGET = 6.0;
396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
397 | PRODUCT_NAME = "$(TARGET_NAME)";
398 | };
399 | name = Debug;
400 | };
401 | 36A5AE4D1B4627E100DF4CD0 /* Release */ = {
402 | isa = XCBuildConfiguration;
403 | buildSettings = {
404 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
405 | INFOPLIST_FILE = IMYWebView/Info.plist;
406 | IPHONEOS_DEPLOYMENT_TARGET = 6.0;
407 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
408 | PRODUCT_NAME = "$(TARGET_NAME)";
409 | };
410 | name = Release;
411 | };
412 | 36A5AE4F1B4627E100DF4CD0 /* Debug */ = {
413 | isa = XCBuildConfiguration;
414 | buildSettings = {
415 | BUNDLE_LOADER = "$(TEST_HOST)";
416 | FRAMEWORK_SEARCH_PATHS = (
417 | "$(SDKROOT)/Developer/Library/Frameworks",
418 | "$(inherited)",
419 | );
420 | GCC_PREPROCESSOR_DEFINITIONS = (
421 | "DEBUG=1",
422 | "$(inherited)",
423 | );
424 | INFOPLIST_FILE = IMYWebViewTests/Info.plist;
425 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
426 | PRODUCT_NAME = "$(TARGET_NAME)";
427 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IMYWebView.app/IMYWebView";
428 | };
429 | name = Debug;
430 | };
431 | 36A5AE501B4627E100DF4CD0 /* Release */ = {
432 | isa = XCBuildConfiguration;
433 | buildSettings = {
434 | BUNDLE_LOADER = "$(TEST_HOST)";
435 | FRAMEWORK_SEARCH_PATHS = (
436 | "$(SDKROOT)/Developer/Library/Frameworks",
437 | "$(inherited)",
438 | );
439 | INFOPLIST_FILE = IMYWebViewTests/Info.plist;
440 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
441 | PRODUCT_NAME = "$(TARGET_NAME)";
442 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IMYWebView.app/IMYWebView";
443 | };
444 | name = Release;
445 | };
446 | /* End XCBuildConfiguration section */
447 |
448 | /* Begin XCConfigurationList section */
449 | 36A5AE201B4627E100DF4CD0 /* Build configuration list for PBXProject "IMYWebView" */ = {
450 | isa = XCConfigurationList;
451 | buildConfigurations = (
452 | 36A5AE491B4627E100DF4CD0 /* Debug */,
453 | 36A5AE4A1B4627E100DF4CD0 /* Release */,
454 | );
455 | defaultConfigurationIsVisible = 0;
456 | defaultConfigurationName = Release;
457 | };
458 | 36A5AE4B1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebView" */ = {
459 | isa = XCConfigurationList;
460 | buildConfigurations = (
461 | 36A5AE4C1B4627E100DF4CD0 /* Debug */,
462 | 36A5AE4D1B4627E100DF4CD0 /* Release */,
463 | );
464 | defaultConfigurationIsVisible = 0;
465 | defaultConfigurationName = Release;
466 | };
467 | 36A5AE4E1B4627E100DF4CD0 /* Build configuration list for PBXNativeTarget "IMYWebViewTests" */ = {
468 | isa = XCConfigurationList;
469 | buildConfigurations = (
470 | 36A5AE4F1B4627E100DF4CD0 /* Debug */,
471 | 36A5AE501B4627E100DF4CD0 /* Release */,
472 | );
473 | defaultConfigurationIsVisible = 0;
474 | defaultConfigurationName = Release;
475 | };
476 | /* End XCConfigurationList section */
477 | };
478 | rootObject = 36A5AE1D1B4627E100DF4CD0 /* Project object */;
479 | }
480 |
--------------------------------------------------------------------------------