Skip to content

Commit

Permalink
替换部分WKWebView
Browse files Browse the repository at this point in the history
  • Loading branch information
hehai committed Mar 10, 2019
1 parent e92e13d commit 60e19a1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 98 deletions.
4 changes: 0 additions & 4 deletions RSChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
72BDB3771C2A3584002AE29F /* RSOtherLoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 72BDB3751C2A3584002AE29F /* RSOtherLoginViewController.m */; };
72BDB3781C2A3584002AE29F /* RSOtherLoginViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 72BDB3761C2A3584002AE29F /* RSOtherLoginViewController.xib */; };
72BDB37C1C2A52CA002AE29F /* RSQuestionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 72BDB37A1C2A52CA002AE29F /* RSQuestionViewController.m */; };
72BDB37D1C2A52CA002AE29F /* RSQuestionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 72BDB37B1C2A52CA002AE29F /* RSQuestionViewController.xib */; };
72C0AC331C11489900C817D2 /* RSAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C0AC321C11489900C817D2 /* RSAnnotation.m */; };
72C0AC371C115B6200C817D2 /* RSBottleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C0AC351C115B6200C817D2 /* RSBottleViewController.m */; };
72C0AC381C115B6200C817D2 /* RSBottleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 72C0AC361C115B6200C817D2 /* RSBottleViewController.xib */; };
Expand Down Expand Up @@ -445,7 +444,6 @@
72BDB3761C2A3584002AE29F /* RSOtherLoginViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RSOtherLoginViewController.xib; sourceTree = "<group>"; };
72BDB3791C2A52CA002AE29F /* RSQuestionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSQuestionViewController.h; sourceTree = "<group>"; };
72BDB37A1C2A52CA002AE29F /* RSQuestionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RSQuestionViewController.m; sourceTree = "<group>"; };
72BDB37B1C2A52CA002AE29F /* RSQuestionViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RSQuestionViewController.xib; sourceTree = "<group>"; };
72C0AC311C11489900C817D2 /* RSAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSAnnotation.h; sourceTree = "<group>"; };
72C0AC321C11489900C817D2 /* RSAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RSAnnotation.m; sourceTree = "<group>"; };
72C0AC341C115B6200C817D2 /* RSBottleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSBottleViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -591,7 +589,6 @@
72BDB3761C2A3584002AE29F /* RSOtherLoginViewController.xib */,
72BDB3791C2A52CA002AE29F /* RSQuestionViewController.h */,
72BDB37A1C2A52CA002AE29F /* RSQuestionViewController.m */,
72BDB37B1C2A52CA002AE29F /* RSQuestionViewController.xib */,
92DC47C6222CD1C500C9686D /* RSCountryListViewController.h */,
92DC47C7222CD1C500C9686D /* RSCountryListViewController.m */,
);
Expand Down Expand Up @@ -1237,7 +1234,6 @@
1B26D6661C3A91F200BFC29C /* RSGameDetailViewController.xib in Resources */,
1B26D6701C3ABC5C00BFC29C /* RSGameDetailACell.xib in Resources */,
9242E2DF2228D8B1008DDC1F /* InfoPlist.strings in Resources */,
72BDB37D1C2A52CA002AE29F /* RSQuestionViewController.xib in Resources */,
72C4046E1C2267F200852B71 /* RSPopView.xib in Resources */,
72ABF3E61BFD78B100EC17C7 /* RSNewsContentCell.xib in Resources */,
7288A5591C1090E3009936A7 /* RSPrivateOtherCell.xib in Resources */,
Expand Down
123 changes: 99 additions & 24 deletions RSChat/Sections/LogInOut/RSQuestionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
//

#import "RSQuestionViewController.h"
#import <WebKit/WebKit.h>
#import "RSChatMacro.h"

@interface RSQuestionViewController ()<UIWebViewDelegate>
@interface RSQuestionViewController ()<WKNavigationDelegate, WKUIDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *questionView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (nonatomic, strong) UILabel *alertLabel;
@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *alertLab;
@property (nonatomic, strong) UIButton *backBtn;

@end

Expand All @@ -25,48 +28,120 @@ @implementation RSQuestionViewController
- (void)viewDidLoad {
[super viewDidLoad];

[self setupNavView];
[self setupMainView];
}

- (void)viewWillDisappear:(BOOL)animated {
[_webView stopLoading];
}

#pragma mark - UI

- (void)setupNavView {

_titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, RSStatusBarH, RSScreenW, 44)];
_titleLab.text = @"placeholder";
_titleLab.font = [UIFont systemFontOfSize:18];
_titleLab.textColor = [UIColor greenColor];
_titleLab.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:_titleLab];

if (self.titleText.length != 0) {
self.titleLabel.text = self.titleText;
self.titleLab.text = self.titleText;
} else {
self.titleLabel.text = @"登录问题";
self.titleLab.text = @"登录问题";
}

_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_backBtn.frame = CGRectMake(0, RSStatusBarH, 80, 44);
_backBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_backBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[_backBtn setTitle:@"取消" forState:UIControlStateNormal];
[_backBtn addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_backBtn];
}

- (void)setupMainView {

if (self.url == nil) {
self.url = [NSURL URLWithString:@"https://support.weixin.qq.com/security/readtemplate?t=page/login_optimized__w_index&lang=zh_CN"];
}

_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, RSNavBarH, RSScreenW, RSScreenH-RSNavBarH)];
[self.view addSubview:_webView];

_webView.navigationDelegate = self;
_webView.UIDelegate = self;
[_webView loadRequest:[NSURLRequest requestWithURL:_url]];
}

#pragma mark - Action

self.questionView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:self.url];
[self.questionView loadRequest:request];
- (void)goBack:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
[self.questionView stopLoading];
#pragma mark - WKUIDelegate

- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
return [[WKWebView alloc] init];
}

#pragma mark - Action
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
completionHandler();
}

- (IBAction)goback:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler {
completionHandler(YES);
}

- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler {
completionHandler(@"http");
}

#pragma mark - webView Delegate
#pragma mark - WKNavigationDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// ...
return YES;
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSLog(@"%@",navigationAction.request.URL.absoluteString);

decisionHandler(WKNavigationActionPolicyAllow);
//decisionHandler(WKNavigationActionPolicyCancel);
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
[self showHUD];
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
NSLog(@"%@",navigationResponse.response.URL.absoluteString);

decisionHandler(WKNavigationResponsePolicyAllow);
//decisionHandler(WKNavigationResponsePolicyCancel);
}

- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {

}

- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation {

}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self hideHUD];
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {

}

- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation {

}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {

}

- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[self hideHUD];
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler {
completionHandler(NSURLSessionAuthChallengeUseCredential, nil);
}

@end
69 changes: 0 additions & 69 deletions RSChat/Sections/LogInOut/RSQuestionViewController.xib

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];

RSQuestionViewController *questionVC = [[RSQuestionViewController alloc] initWithNibName:@"RSQuestionViewController" bundle:[NSBundle mainBundle]];
RSQuestionViewController *questionVC = [[RSQuestionViewController alloc] init];

if (indexPath.section == 0) {
questionVC.url = [NSURL URLWithString:@"http://m.meilishuo.com/"];
Expand Down

0 comments on commit 60e19a1

Please sign in to comment.