UserCenterViewController1.m 9.6 KB

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