From 67d821f4949c9869137bc7cb85418a21fc48792e Mon Sep 17 00:00:00 2001 From: allez <305670599@qq.com> Date: 星期四, 22 四月 2021 10:49:14 +0800 Subject: [PATCH] 8908 【主干】ios问题 解决UIViewWeb淘汰, --- Channel/IOS/qkbt2game/Plugins/The2thWorldSDK/UniversalSDK.mm | 71 ++++++++++++++++++++++------------- 1 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Channel/IOS/qkbt2game/Plugins/The2thWorldSDK/UniversalSDK.mm b/Channel/IOS/qkbt2game/Plugins/The2thWorldSDK/UniversalSDK.mm index e8c96b3..3d816c3 100644 --- a/Channel/IOS/qkbt2game/Plugins/The2thWorldSDK/UniversalSDK.mm +++ b/Channel/IOS/qkbt2game/Plugins/The2thWorldSDK/UniversalSDK.mm @@ -14,9 +14,6 @@ #import "SystemConfiguration/CaptiveNetwork.h" #import <SMPCQuickSDK/SMPCQuickSDK.h> -@interface UniversalSDK()<UIWebViewDelegate> -@end - @implementation UniversalSDK #define CHANNEL_NUM 1 @@ -31,6 +28,20 @@ static NSString* sGameID; static NSString* sUserName; static NSThread* _thread; + +-(id)init +{ + self = [super init]; + + m_fakeUIWebView = [[WKWebView alloc] initWithFrame:CGRectZero]; + NSURL *url = [NSURL URLWithString:@"www.baidu.com"]; + NSURLRequest *request = [NSURLRequest requestWithURL:url + cachePolicy:NSURLRequestUseProtocolCachePolicy + timeoutInterval:10.f]; + [m_fakeUIWebView loadRequest:request]; + + return self; +} -(void) Init { @@ -60,16 +71,18 @@ } // 鍙栧緱UserAgent - UIWebView* _webView = [[UIWebView alloc] initWithFrame:CGRectZero]; - NSString* _userAgent = [_webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; - - // 鍙戦�佽澶囦俊鎭� - NSMutableDictionary *_dict = [NSMutableDictionary dictionaryWithObjectsAndKeys: - _uniqueID,@"unique_id", - _idfa,@"android_id", - [NSNumber numberWithInt:S2U_DeviceInfo],@"code", - _userAgent,@"userAgent",nil]; - [self SendMessageToUnity:_dict]; + [m_fakeUIWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable userAgent, NSError * _Nullable error) { + + NSLog(@"%@", userAgent); + NSString* _userAgent = [NSString stringWithFormat:@"%@", userAgent]; + // 鍙戦�佽澶囦俊鎭� + NSMutableDictionary *_dict = [NSMutableDictionary dictionaryWithObjectsAndKeys: + _uniqueID,@"unique_id", + _idfa,@"android_id", + [NSNumber numberWithInt:S2U_DeviceInfo],@"code", + _userAgent,@"userAgent",nil]; + [self SendMessageToUnity:_dict]; + }]; } -(void)SendMessageToUnity:(NSDictionary*)dict @@ -129,13 +142,15 @@ float _offsetX = (_bounds.size.width - _width) * .5f; float _offsetY = (_bounds.size.height - _height) * .5f; - m_UIWebView = [[UIWebView alloc] initWithFrame:CGRectMake(_offsetX, _offsetY, _width, _height)]; - m_UIWebView.delegate = self; - m_UIWebView.scalesPageToFit = YES ; + m_UIWebView = [[WKWebView alloc] initWithFrame:CGRectMake(_offsetX, _offsetY, _width, _height)]; + m_UIWebView.UIDelegate = self; + m_UIWebView.navigationDelegate = self ; m_UIWebView.scrollView.scrollEnabled = YES; m_UIWebView.scrollView.bounces = NO; NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [m_UIWebView loadRequest:request]; + + } -(void) btnClick:(UIButton*)sender { @@ -152,12 +167,10 @@ m_UIWebView = NULL; } --(void)webViewDidStartLoad:(UIWebView *)webView{ -} --(void)webViewDidFinishLoad:(UIWebView *)webView{ +//-(void)webViewDidFinishLoad:(WKWebView *)webView{ +- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{ - [UnityGetMainWindow().rootViewController.view addSubview:m_UIWebView]; CGRect _bounds = UnityGetMainWindow().bounds; float _scale = _bounds.size.width / 1334; @@ -166,7 +179,7 @@ float _height = 560 * _scale; m_CloseBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [m_CloseBtn setFrame:CGRectMake(_width - 455 * _scale, _height - 86 * _scale, 180 * _scale, 72 * _scale)]; + [m_CloseBtn setFrame:CGRectMake(_width - 600 * _scale, _height - 86 * _scale, 360 * _scale, 72 * _scale)]; [m_CloseBtn setTitle:@"鎴戠煡閬撲簡" forState:UIControlStateNormal]; NSString *_bundlePath = [[NSBundle mainBundle] pathForResource:@"The2thWorldRES.bundle" ofType:nil]; @@ -178,9 +191,9 @@ [m_CloseBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [m_UIWebView addSubview:m_CloseBtn]; -} - --(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ + + UIView *view = UnityGetGLViewController().view; + [view addSubview:m_UIWebView]; } -(void)QuickSDKInit:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @@ -245,8 +258,12 @@ NSDictionary *userInfo = [notify userInfo]; if (error == 0) { NSString *uid = [[SMPCQuickSDK defaultInstance] userId]; - NSString *cid =[[SMPCQuickSDK defaultInstance] getConfigValue:@"cid"]; - NSString *gameUID = [NSString stringWithFormat:@"%@%@%@", uid,@"@",cid]; + NSString *channel =[[SMPCQuickSDK defaultInstance] getConfigValue:@"channel"]; + NSString *gameUID; + if(channel&&[channel length]!=0) + gameUID = [NSString stringWithFormat:@"%@%@%@", uid,@"@",channel]; + else + gameUID = [NSString stringWithFormat:@"%@@%d", uid, [SMPCQuickSDK defaultInstance].channelType]; NSString *UserName = [[SMPCQuickSDK defaultInstance] userId]; //鑾峰彇user_token锛岀敤浜庝粠鏈嶅姟鍣ㄥ幓楠岃瘉鐢ㄦ埛淇℃伅 NSString *user_token = userInfo[kSmpcQuickSDKKeyUserToken]; @@ -531,7 +548,7 @@ frame += s_frameSize; rbytes += length + sizeof(char); len -= s_frameSize; - totalSize += length; + totalSize += (length+1); } opus_encoder_destroy(enc); return totalSize; -- Gitblit v1.8.0