优化,防止混沌代码时出错
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
buildConfiguration = "Release"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
|
@@ -173,7 +173,7 @@
|
||||
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
_avatarImageView.layer.masksToBounds = YES;
|
||||
_avatarImageView.layer.cornerRadius = 60 / 2;
|
||||
_avatarImageView.backgroundColor = UIColor.blueColor;
|
||||
|
||||
}
|
||||
return _avatarImageView;
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ NSString * const kJSGetUid = @"getUid";
|
||||
@interface YMWebViewController ()<WKNavigationDelegate, WKScriptMessageHandler>
|
||||
@property (strong, nonatomic) WKWebView *webview;
|
||||
@property (strong, nonatomic) UIProgressView *progressView;
|
||||
@property (nonatomic, strong) WKUserContentController *userContentController;
|
||||
@property (nonatomic, strong) WKUserContentController *mew_userContentController;
|
||||
|
||||
@end
|
||||
|
||||
@@ -220,18 +220,18 @@ NSString * const kJSGetUid = @"getUid";
|
||||
NSString *realCookie = [NSString stringWithFormat:@"%@=%@",@"uid",uid];
|
||||
|
||||
WKUserScript *cookieScript = [[WKUserScript alloc] initWithSource: [NSString stringWithFormat:@"document.cookie = '%@';", realCookie] injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
|
||||
[self.userContentController addUserScript:cookieScript];
|
||||
[self.mew_userContentController addUserScript:cookieScript];
|
||||
///禁止缩放
|
||||
NSString *scaleJs = @"$('meta[name=description]').remove(); $('head').append( '<meta name=\"viewport\" content=\"width=device-width, initial-scale=1,user-scalable=no\">' );";
|
||||
WKUserScript *scaleScript = [[WKUserScript alloc] initWithSource:scaleJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
|
||||
[self.userContentController addUserScript:scaleScript];
|
||||
[self.mew_userContentController addUserScript:scaleScript];
|
||||
|
||||
//根据生成的WKUserScript对象,初始化WKWebViewConfiguration
|
||||
configuration.preferences.javaScriptEnabled = YES;
|
||||
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
|
||||
configuration.preferences.minimumFontSize = 10;
|
||||
configuration.selectionGranularity = WKSelectionGranularityCharacter;
|
||||
configuration.userContentController = self.userContentController;
|
||||
configuration.userContentController = self.mew_userContentController;
|
||||
|
||||
CGSize size = [UIScreen mainScreen].bounds.size;
|
||||
_webview = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, size.width,size.height) configuration:configuration];
|
||||
@@ -267,13 +267,13 @@ NSString * const kJSGetUid = @"getUid";
|
||||
return _webview;
|
||||
}
|
||||
|
||||
- (WKUserContentController *)userContentController{
|
||||
if (!_userContentController) {
|
||||
- (WKUserContentController *)mew_userContentController{
|
||||
if (!_mew_userContentController) {
|
||||
//自定义的WKScriptMessageHandler 是为了解决内存不释放的问题
|
||||
WeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[WeakWebViewScriptMessageDelegate alloc] initWithDelegate:self];
|
||||
_userContentController = [[WKUserContentController alloc] init];
|
||||
_mew_userContentController = [[WKUserContentController alloc] init];
|
||||
// 获取uid
|
||||
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetUid];
|
||||
[_mew_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetUid];
|
||||
// 分享面板
|
||||
// [_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenSharePage];
|
||||
// // 钱包页面
|
||||
@@ -315,6 +315,6 @@ NSString * const kJSGetUid = @"getUid";
|
||||
// [_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kCheckResultFinish];
|
||||
// [_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kOpenNativeTarotPay];
|
||||
}
|
||||
return _userContentController;
|
||||
return _mew_userContentController;
|
||||
}
|
||||
@end
|
||||
|
Reference in New Issue
Block a user