UserCenterViewController2.m 9.3 KB

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