// // UserCenterViewController.m // XenonSDK // // Created by SAGESSE on 2019/5/30. // Copyright © 2019 SAGESSE. All rights reserved. // #import "XenonSDK.h" #import "RootViewController.h" #import "UserCenterViewController1.h" #import "XSTool.h" #import "RootViewController.h" #import "UserLoginPhoneViewController.h" #import #import #import #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.width #define DT_IS_IPHONEX_XS (SCREEN_HEIGHT == 812.f)//是否是iPhoneX、iPhoneXS #define DT_IS_IPHONEXR_XSMax (SCREEN_HEIGHT == 896.f)//是否是iPhoneXR、iPhoneX Max #define DT_IS_IPHONE12_ProMax (SCREEN_HEIGHT == 926.f) #define IS_IPHONEX_SET (DT_IS_IPHONEX_XS||DT_IS_IPHONEXR_XSMax||DT_IS_IPHONE12_ProMax)//是否是iPhoneX系列手机 #define State_Bar_H ( ( ![[UIApplication sharedApplication] isStatusBarHidden] ) ? [[UIApplication sharedApplication] statusBarFrame].size.height : (IS_IPHONEX_SET?44.f:20.f)) @interface UserCenterViewController1 () @property(nonatomic, strong)UIWebView* webView; @end @implementation UserCenterViewController1 - (void)sdk_dismissViewController:(id)sender { [super sdk_dismissViewController:sender]; if (self.callback != nil) { self.callback(); } } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //处理iphoneX屏幕尺寸 if (State_Bar_H == 44.f) { //NSLog(@"iphoneX系列~"); self.leftConstraint.constant = State_Bar_H; }else{ self.leftConstraint.constant = 0; } XSUser* user = XenonSDK.sharedSDK.user; // -[UIWebView initWithFrame:] self.webView = (UIWebView *)[[NSClassFromString(fqsd(@"iB0AAM3C0eDe0+fk9wA=")) alloc] initWithFrame:self.containerView.bounds]; if (self.webView == nil) { return; } self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.webView.backgroundColor = UIColor.clearColor; self.webView.clipsToBounds = YES; self.webView.layer.cornerRadius = 12.0; [self.webView setValue:self forKey:@"delegate"]; [self.containerView addSubview:self.webView]; NSURL* url = nil; if (self.custom == nil) { //获取本地语言 NSString *preferredLang = [XSTool getCurrentSystemLauguage]; //NSURLComponents* cmp = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"%@/float/portrait/userinfo.html", XSNetwork.baseURL]]; NSURLComponents* cmp = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"%@/float/landscape/%@/userinfo.html",XSNetwork.baseURL,preferredLang]]; NSDictionary* json = [XSNetwork bodyWithParameters:@{@"phone":@"",@"uid":user.uid?:@"",@"userName":user.userName?:@""}]; NSString* str = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:json options:0 error:nil] encoding:NSUTF8StringEncoding]; cmp.queryItems = @[[NSURLQueryItem queryItemWithName:@"jsonData" value:str], [NSURLQueryItem queryItemWithName:@"v" value:@"1"]]; url = cmp.URL; } else { url = [NSURL URLWithString:self.custom]; } // -[UIWebView loadRequest:] ((void(*)(id,SEL,id))objc_msgSend)(self.webView, NSSelectorFromString(fqsd(@"rEsAAMHQ0pnAxLe7qr7L0AI=")), [NSURLRequest requestWithURL:url]); } - (BOOL)webView:(id)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(NSInteger)navigationType { // Read the parameter. NSString* scheme = request.URL.scheme; if (scheme.length == 0) { return YES; } NSString *currentURL= request.URL.absoluteString; if ([currentURL hasPrefix:@"copy://"]) { //line账号复制 NSString *newStr = [currentURL stringByReplacingOccurrencesOfString:@"copy://" withString:@""]; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = newStr; [XSNetwork showHudSuccess:@"复制成功!"]; return NO; } //facebook跳转到浏览器网页 if ([currentURL hasPrefix:@"fb://"]) { NSArray *arr = [currentURL componentsSeparatedByString:@"href="]; NSString *facebookUrl = [arr lastObject]; if (facebookUrl.length > 0) { if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:facebookUrl]]) { [[UIApplication sharedApplication ] openURL:[NSURL URLWithString:facebookUrl]]; }else{ [XSNetwork showHudSuccess:@"未安装Facebook应用!"]; } } return NO; } // Process event if ([scheme isEqual:@"app"]) { // Exit game in webview. if ([request.URL.host isEqual:@"exitAccount"]) { [XenonSDK.sharedSDK logoutWithComplete:^{ if (XenonSDK.sharedSDK.sdk_logoutCallback != nil) { XenonSDK.sharedSDK.sdk_logoutCallback(nil); } }]; [self sdk_dismissViewController:webView]; return NO; } //change account if ([request.URL.host isEqual:@"switchAccount"]) { [self sdk_dismissViewController:webView]; [XenonSDK.sharedSDK logoutWithComplete:^{ //封神传说cp平台,收到登出通知后会调用一次登录接口, 这里重复了.注释掉 XSUser.history = nil; [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError *error) { }]; }]; return NO; } //绑定Facebook账号 if ([request.URL.host isEqual:@"bindFackBook"]) { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; //public_profile [login logInWithPermissions: @[@"public_profile",@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { NSLog(@"facebook login result.grantedPermissions = %@,error = %@",result.grantedPermissions,error); if (error) { [XSNetwork showHudFailure:error]; NSLog(@"Process error"); } else if (result.isCancelled) { NSLog(@"Cancelled"); [XSNetwork showHudFailure:@"Cancelled"]; } else { NSLog(@"Logged in"); FBSDKAccessToken *token = result.token; NSString *appid = token.appID; NSString *playerid = token.userID; NSString *tokens = token.tokenString; [XSNetwork bindFacebookWithToken:tokens appId:appid playerId:playerid complete:^(id object, NSError *error) { if (error != nil) { [XSNetwork showHudFailure:error]; return; }else{ //绑定成功,重新刷新页面 [self.webView reload]; } }]; } }]; return NO; } //Line 绑定 if ([request.URL.host isEqual:@"bindLine"]) { [XSNetwork showHudSuccess:@"功能开发中..."]; return NO; } return YES; } // Process click back. if ([scheme isEqual:[NSString stringWithFormat:@"app%@", XenonSDK.sharedSDK.appId]]) { [self sdk_dismissViewController:webView]; return NO; } // Check to see if you start with these characters. NSArray* rewrites = @[@"http", @"https"]; if ([rewrites containsObject:scheme]) { return YES; } // -[UIApplication openURL:] ((void(*)(id,SEL,id))objc_msgSend)(UIApplication.sharedApplication, NSSelectorFromString(fqsd(@"p2cAAMrAyrKwq5rIAA==")), request.URL); return NO; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.otherView.hidden = YES; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.otherView.hidden = NO; } - (BOOL)prefersUnifiedBackground { return NO; } #pragma mark - clicked Action - (IBAction)clickedAction:(UIButton *)sender { //已经选中,不操作 if (sender.selected) { return; } sender.selected = !sender.selected; if (sender.selected) { NSInteger tag = sender.tag; [self sendJSForChangePageWith:tag-100]; switch (tag) { case 101: { self.serviceBtn.selected = NO; self.moreBtn.selected = NO; } break; case 102: { self.centerBtn.selected = NO; self.moreBtn.selected = NO; } break; case 103: { self.centerBtn.selected = NO; self.serviceBtn.selected = NO; } break; default: break; } } } #pragma mark - 切换页面 -(void)sendJSForChangePageWith:(NSInteger)num { [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"showPage(%ld);",(long)num]]; } @end