1. 优化礼物面板加载
2. 百顺游戏 debug 环境添加 vConsole
This commit is contained in:
@@ -47,7 +47,7 @@ NSString * const kMSGameLoaded = @"gameLoaded";
|
||||
|
||||
|
||||
@interface MSRoomGameWebVC () <WKNavigationDelegate, WKScriptMessageHandler,WKUIDelegate>
|
||||
@property (strong, nonatomic) WKWebView *webview;
|
||||
@property (strong, nonatomic) WKWebView *webView;
|
||||
@property (strong, nonatomic) UIProgressView *progressView;
|
||||
@property (nonatomic, strong) WKUserContentController *ms_userContentController;
|
||||
@property (nonatomic,weak) id<RoomHostDelegate> hostDelegate;
|
||||
@@ -92,7 +92,7 @@ NSString * const kMSGameLoaded = @"gameLoaded";
|
||||
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kMSDestroy];
|
||||
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kMSGameRecharge];
|
||||
[_ms_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kMSGameLoaded];
|
||||
|
||||
|
||||
|
||||
WKWebViewConfiguration *config = [WKWebViewConfiguration new];
|
||||
config.allowsInlineMediaPlayback = YES;
|
||||
@@ -110,30 +110,58 @@ NSString * const kMSGameLoaded = @"gameLoaded";
|
||||
int ScreenHeight = [[UIScreen mainScreen] bounds].size.height;
|
||||
int ScreenWidth = [[UIScreen mainScreen] bounds].size.width;
|
||||
|
||||
self.webview = [[WKWebView alloc] initWithFrame:CGRectMake(0,0,
|
||||
self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0,0,
|
||||
ScreenWidth, ScreenHeight) configuration:config];
|
||||
[self.webview.scrollView setBackgroundColor:[UIColor clearColor]];
|
||||
[self.webview setBackgroundColor:[UIColor clearColor]];
|
||||
[self.webview setUIDelegate:self];
|
||||
self.webview.navigationDelegate = self;
|
||||
[self.webView.scrollView setBackgroundColor:[UIColor clearColor]];
|
||||
[self.webView setBackgroundColor:[UIColor clearColor]];
|
||||
[self.webView setUIDelegate:self];
|
||||
self.webView.navigationDelegate = self;
|
||||
//设置⽹⻚透明
|
||||
[self.webview setOpaque:NO];
|
||||
[self.webView setOpaque:NO];
|
||||
//设置⽹⻚全屏
|
||||
if (@available(iOS 11.0, *)) {
|
||||
self.webview.scrollView.contentInsetAdjustmentBehavior =
|
||||
self.webView.scrollView.contentInsetAdjustmentBehavior =
|
||||
UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
[self.view addSubview:self.webview];
|
||||
[self.view addSubview:self.webView];
|
||||
|
||||
NSString *h5Url = self.gameModel.skipContent;
|
||||
NSURL *url = [NSURL URLWithString:h5Url];
|
||||
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
|
||||
[self.webview loadRequest:request];
|
||||
[self.webView loadRequest:request];
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
||||
#if DEBUG
|
||||
NSString *fileName = @"vconsole.min.js"; // 你要查找的文件名
|
||||
NSString *directory = [[NSBundle mainBundle] resourcePath];
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:directory];
|
||||
NSString *filePath;
|
||||
|
||||
for (NSString *path in enumerator) {
|
||||
if ([[path lastPathComponent] containsString:fileName]) {
|
||||
filePath = [directory stringByAppendingPathComponent:path];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filePath.length > 0) {
|
||||
NSString *vConsoleScript = [NSString stringWithContentsOfFile:filePath
|
||||
encoding:NSUTF8StringEncoding error:nil];
|
||||
[self.webView evaluateJavaScript:vConsoleScript completionHandler:nil];
|
||||
|
||||
// 初始化 vConsole
|
||||
NSString *initVConsoleScript = @"var vConsole = new VConsole();";
|
||||
[self.webView evaluateJavaScript:initVConsoleScript completionHandler:nil];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
|
||||
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
|
||||
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
|
||||
});
|
||||
@@ -143,6 +171,7 @@ NSString * const kMSGameLoaded = @"gameLoaded";
|
||||
// 调⽤JS
|
||||
- (void)callJs:(NSString*)method withJavaScriptValue:(nullable id)arguments
|
||||
{
|
||||
@kWeakify(self);
|
||||
if (arguments) {
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:arguments
|
||||
options:(NSJSONWritingPrettyPrinted) error:nil];
|
||||
@@ -150,15 +179,17 @@ NSString * const kMSGameLoaded = @"gameLoaded";
|
||||
encoding:NSUTF8StringEncoding];
|
||||
NSString *jsMethods = [NSString stringWithFormat:@"%@(%@)", method,
|
||||
jsonStr];
|
||||
[self.webview evaluateJavaScript:jsMethods completionHandler:^(id
|
||||
[self.webView evaluateJavaScript:jsMethods completionHandler:^(id
|
||||
_Nullable resp, NSError * _Nullable error) {
|
||||
@kStrongify(self);
|
||||
NSLog(@"error = %@ , response = %@",error, resp);
|
||||
[self.backBtn removeFromSuperview];
|
||||
}];
|
||||
} else {
|
||||
NSString *jsMethods = [NSString stringWithFormat:@"%@({})", method];
|
||||
[self.webview evaluateJavaScript:jsMethods completionHandler:^(id
|
||||
[self.webView evaluateJavaScript:jsMethods completionHandler:^(id
|
||||
_Nullable resp, NSError * _Nullable error) {
|
||||
@kStrongify(self);
|
||||
NSLog(@"error = %@ , response = %@",error, resp);
|
||||
[self.backBtn removeFromSuperview];
|
||||
}];
|
||||
@@ -189,7 +220,7 @@ NSString * const kMSGameLoaded = @"gameLoaded";
|
||||
*)userContentController
|
||||
didReceiveScriptMessage:(WKScriptMessage *)message
|
||||
{
|
||||
NSString* method = [NSString stringWithFormat:@"%@:", message.name];
|
||||
// NSString* method = [NSString stringWithFormat:@"%@:", message.name];
|
||||
NSDictionary *dicBody = [self dictionaryWithJsonString:message.body];
|
||||
|
||||
if ([message.name isEqualToString:kMSGetConfig]) {
|
||||
|
Reference in New Issue
Block a user