UserCenterViewController1.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. //
  2. // UserCenterViewController.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/30.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XenonSDK.h"
  9. #import "RootViewController.h"
  10. #import "UserCenterViewController1.h"
  11. #import "XSTool.h"
  12. #import "RootViewController.h"
  13. #import "UserLoginPhoneViewController.h"
  14. #import <objc/message.h>
  15. #import <FBSDKCoreKit/FBSDKCoreKit.h>
  16. #import <FBSDKLoginKit/FBSDKLoginKit.h>
  17. #import "NSBundle+KODLocalizable.h"
  18. #import "KODCommonConst.h"
  19. #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.width
  20. #define DT_IS_IPHONEX_XS (SCREEN_HEIGHT == 812.f)//是否是iPhoneX、iPhoneXS
  21. #define DT_IS_IPHONEXR_XSMax (SCREEN_HEIGHT == 896.f)//是否是iPhoneXR、iPhoneX Max
  22. #define DT_IS_IPHONE12_ProMax (SCREEN_HEIGHT == 926.f)
  23. #define IS_IPHONEX_SET (DT_IS_IPHONEX_XS||DT_IS_IPHONEXR_XSMax||DT_IS_IPHONE12_ProMax)//是否是iPhoneX系列手机
  24. #define State_Bar_H ( ( ![[UIApplication sharedApplication] isStatusBarHidden] ) ? [[UIApplication sharedApplication] statusBarFrame].size.height : (IS_IPHONEX_SET?44.f:20.f))
  25. @interface UserCenterViewController1 ()
  26. @property(nonatomic, strong)UIWebView* webView;
  27. @end
  28. @implementation UserCenterViewController1
  29. - (void)sdk_dismissViewController:(id)sender {
  30. [super sdk_dismissViewController:sender];
  31. if (self.callback != nil) {
  32. self.callback();
  33. }
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. // Do any additional setup after loading the view.
  38. //处理iphoneX屏幕尺寸
  39. if (State_Bar_H == 44.f) {
  40. //NSLog(@"iphoneX系列~");
  41. self.leftConstraint.constant = State_Bar_H;
  42. }else{
  43. self.leftConstraint.constant = 0;
  44. }
  45. XSUser* user = XenonSDK.sharedSDK.user;
  46. // -[UIWebView initWithFrame:]
  47. self.webView = (UIWebView *)[[NSClassFromString(fqsd(@"iB0AAM3C0eDe0+fk9wA=")) alloc] initWithFrame:self.containerView.bounds];
  48. if (self.webView == nil) {
  49. return;
  50. }
  51. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  52. self.webView.backgroundColor = UIColor.clearColor;
  53. self.webView.clipsToBounds = YES;
  54. self.webView.layer.cornerRadius = 12.0;
  55. [self.webView setValue:self forKey:@"delegate"];
  56. [self.containerView addSubview:self.webView];
  57. NSURL* url = nil;
  58. if (self.custom == nil) {
  59. //获取本地语言
  60. //NSString *preferredLang = [XSTool getCurrentSystemLauguage];
  61. //NSURLComponents* cmp = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"%@/float/portrait/userinfo.html", XSNetwork.baseURL]];
  62. //PS:旧版的获取手机系统语言,去掉.preferredLang.写成固定url格式的.服务器去判断,
  63. NSURLComponents* cmp = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"%@/float/landscape/zh/userinfo.html",XSNetwork.baseURL]];
  64. NSDictionary* json = [XSNetwork bodyWithParameters:@{@"phone":@"",@"uid":user.uid?:@"",@"userName":user.userName?:@""}];
  65. NSString* str = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:json options:0 error:nil] encoding:NSUTF8StringEncoding];
  66. cmp.queryItems = @[[NSURLQueryItem queryItemWithName:@"jsonData" value:str],
  67. [NSURLQueryItem queryItemWithName:@"v" value:@"1"]];
  68. url = cmp.URL;
  69. } else {
  70. url = [NSURL URLWithString:self.custom];
  71. }
  72. // -[UIWebView loadRequest:]
  73. ((void(*)(id,SEL,id))objc_msgSend)(self.webView, NSSelectorFromString(fqsd(@"rEsAAMHQ0pnAxLe7qr7L0AI=")), [NSURLRequest requestWithURL:url]);
  74. }
  75. - (BOOL)webView:(id)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(NSInteger)navigationType {
  76. // Read the parameter.
  77. NSString* scheme = request.URL.scheme;
  78. if (scheme.length == 0) {
  79. return YES;
  80. }
  81. NSString *currentURL= request.URL.absoluteString;
  82. if ([currentURL hasPrefix:@"copy://"]) {
  83. //line账号复制
  84. NSString *newStr = [currentURL stringByReplacingOccurrencesOfString:@"copy://" withString:@""];
  85. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  86. pasteboard.string = newStr;
  87. //复制成功
  88. NSString *str = [NSBundle KOD_localizedStringForKey:CopySuccess];
  89. [XSNetwork showHudSuccess:str];
  90. return NO;
  91. }
  92. //facebook跳转到浏览器网页
  93. if ([currentURL hasPrefix:@"fb://"]) {
  94. NSArray *arr = [currentURL componentsSeparatedByString:@"href="];
  95. NSString *facebookUrl = [arr lastObject];
  96. if (facebookUrl.length > 0) {
  97. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:facebookUrl]]) {
  98. [[UIApplication sharedApplication ] openURL:[NSURL URLWithString:facebookUrl]];
  99. }else{
  100. //未安装Facebook应用
  101. NSString *str = [NSBundle KOD_localizedStringForKey:NoInstallFacebookApp];
  102. [XSNetwork showHudSuccess:str];
  103. }
  104. }
  105. return NO;
  106. }
  107. // Process event
  108. if ([scheme isEqual:@"app"]) {
  109. // Exit game in webview.
  110. if ([request.URL.host isEqual:@"exitAccount"]) {
  111. [XenonSDK.sharedSDK logoutWithComplete:^{
  112. if (XenonSDK.sharedSDK.sdk_logoutCallback != nil) {
  113. XenonSDK.sharedSDK.sdk_logoutCallback(nil);
  114. }
  115. }];
  116. [self sdk_dismissViewController:webView];
  117. return NO;
  118. }
  119. //change account
  120. if ([request.URL.host isEqual:@"switchAccount"]) {
  121. [self sdk_dismissViewController:webView];
  122. [XenonSDK.sharedSDK logoutWithComplete:^{
  123. //封神传说cp平台,收到登出通知后会调用一次登录接口, 这里重复了.注释掉
  124. XSUser.history = nil;
  125. [XenonSDK.sharedSDK loginWithComplete:^(id user, NSError *error) {
  126. }];
  127. }];
  128. return NO;
  129. }
  130. //绑定Facebook账号
  131. if ([request.URL.host isEqual:@"bindFackBook"]) {
  132. FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
  133. //public_profile
  134. [login logInWithPermissions: @[@"public_profile",@"email"]
  135. fromViewController:self
  136. handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
  137. NSLog(@"facebook login result.grantedPermissions = %@,error = %@",result.grantedPermissions,error);
  138. if (error) {
  139. [XSNetwork showHudFailure:error];
  140. NSLog(@"Process error");
  141. } else if (result.isCancelled) {
  142. NSLog(@"Cancelled");
  143. [XSNetwork showHudFailure:@"Cancelled"];
  144. } else {
  145. NSLog(@"Logged in");
  146. FBSDKAccessToken *token = result.token;
  147. NSString *appid = token.appID;
  148. NSString *playerid = token.userID;
  149. NSString *tokens = token.tokenString;
  150. [XSNetwork bindFacebookWithToken:tokens appId:appid playerId:playerid complete:^(id object, NSError *error) {
  151. if (error != nil) {
  152. [XSNetwork showHudFailure:error];
  153. return;
  154. }else{
  155. //绑定成功,重新刷新页面
  156. [self.webView reload];
  157. }
  158. }];
  159. }
  160. }];
  161. return NO;
  162. }
  163. //Line 绑定
  164. if ([request.URL.host isEqual:@"bindLine"]) {
  165. //功能开发中
  166. NSString *str = [NSBundle KOD_localizedStringForKey:FunctionDeveloping];
  167. [XSNetwork showHudSuccess:str];
  168. return NO;
  169. }
  170. return YES;
  171. }
  172. // Process click back.
  173. if ([scheme isEqual:[NSString stringWithFormat:@"app%@", XenonSDK.sharedSDK.appId]]) {
  174. [self sdk_dismissViewController:webView];
  175. return NO;
  176. }
  177. // Check to see if you start with these characters.
  178. NSArray* rewrites = @[@"http", @"https"];
  179. if ([rewrites containsObject:scheme]) {
  180. return YES;
  181. }
  182. // -[UIApplication openURL:]
  183. ((void(*)(id,SEL,id))objc_msgSend)(UIApplication.sharedApplication, NSSelectorFromString(fqsd(@"p2cAAMrAyrKwq5rIAA==")), request.URL);
  184. return NO;
  185. }
  186. - (void)viewWillAppear:(BOOL)animated {
  187. [super viewWillAppear:animated];
  188. self.otherView.hidden = YES;
  189. }
  190. - (void)viewWillDisappear:(BOOL)animated {
  191. [super viewWillDisappear:animated];
  192. self.otherView.hidden = NO;
  193. }
  194. - (BOOL)prefersUnifiedBackground {
  195. return NO;
  196. }
  197. #pragma mark - clicked Action
  198. - (IBAction)clickedAction:(UIButton *)sender {
  199. //已经选中,不操作
  200. if (sender.selected) {
  201. return;
  202. }
  203. sender.selected = !sender.selected;
  204. if (sender.selected) {
  205. NSInteger tag = sender.tag;
  206. [self sendJSForChangePageWith:tag-100];
  207. switch (tag) {
  208. case 101:
  209. {
  210. self.serviceBtn.selected = NO;
  211. self.moreBtn.selected = NO;
  212. }
  213. break;
  214. case 102:
  215. {
  216. self.centerBtn.selected = NO;
  217. self.moreBtn.selected = NO;
  218. }
  219. break;
  220. case 103:
  221. {
  222. self.centerBtn.selected = NO;
  223. self.serviceBtn.selected = NO;
  224. }
  225. break;
  226. default:
  227. break;
  228. }
  229. }
  230. }
  231. #pragma mark - 切换页面
  232. -(void)sendJSForChangePageWith:(NSInteger)num {
  233. [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"showPage(%ld);",(long)num]];
  234. }
  235. @end