| | |
| | | #import "SystemConfiguration/CaptiveNetwork.h" |
| | | #import <SMPCQuickSDK/SMPCQuickSDK.h> |
| | | |
| | | @interface UniversalSDK()<UIWebViewDelegate> |
| | | @end |
| | | |
| | | @implementation UniversalSDK |
| | | |
| | | #define CHANNEL_NUM 1 |
| | |
| | | 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 |
| | | { |
| | |
| | | } |
| | | |
| | | // 取得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 |
| | |
| | | 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 { |
| | |
| | | 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; |
| | |
| | | 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]; |
| | |
| | | [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 { |
| | |
| | | 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]; |
| | |
| | | frame += s_frameSize; |
| | | rbytes += length + sizeof(char); |
| | | len -= s_frameSize; |
| | | totalSize += length; |
| | | totalSize += (length+1); |
| | | } |
| | | opus_encoder_destroy(enc); |
| | | return totalSize; |