123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- //
- // UserCenterViewController2.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/30.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XenonSDK.h"
- #import "RootViewController.h"
- #import "UserCenterViewController2.h"
- #import "XSTool.h"
- #import "RootViewController.h"
- #import "UserLoginPhoneViewController.h"
- #import <objc/message.h>
- #import <FBSDKCoreKit/FBSDKCoreKit.h>
- #import <FBSDKLoginKit/FBSDKLoginKit.h>
- @interface UserCenterViewController2 ()
- @property(nonatomic, strong)UIWebView* webView;
- @end
- @implementation UserCenterViewController2
- - (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.
-
- 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;
- }
-
- //切换账号
- 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
|