UserCenterViewController2.m 8.8 KB

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