优化,防止混沌代码时出错

This commit is contained in:
liyuhua
2023-11-24 14:50:51 +08:00
parent 6f4610044d
commit 5597016f94
3 changed files with 11 additions and 11 deletions

View File

@@ -31,7 +31,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"

View File

@@ -173,7 +173,7 @@
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = 60 / 2;
_avatarImageView.backgroundColor = UIColor.blueColor;
}
return _avatarImageView;
}

View File

@@ -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];
//WKUserScriptWKWebViewConfiguration
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