123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- //
- // UserCenterViewController.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/30.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XenonSDK.h"
- #import "RootViewController.h"
- #import "UserCenterViewController1.h"
- #import "XSTool.h"
- #import "RootViewController.h"
- #import "UserLoginPhoneViewController.h"
- #import <objc/message.h>
- #import <FBSDKCoreKit/FBSDKCoreKit.h>
- #import <FBSDKLoginKit/FBSDKLoginKit.h>
- #import "NSBundle+KODLocalizable.h"
- #import "KODCommonConst.h"
- #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.width
- #define DT_IS_IPHONEX_XS (SCREEN_HEIGHT == 812.f)//是否是iPhoneX、iPhoneXS
- #define DT_IS_IPHONEXR_XSMax (SCREEN_HEIGHT == 896.f)//是否是iPhoneXR、iPhoneX Max
- #define DT_IS_IPHONE12_ProMax (SCREEN_HEIGHT == 926.f)
- #define IS_IPHONEX_SET (DT_IS_IPHONEX_XS||DT_IS_IPHONEXR_XSMax||DT_IS_IPHONE12_ProMax)//是否是iPhoneX系列手机
- #define State_Bar_H ( ( ![[UIApplication sharedApplication] isStatusBarHidden] ) ? [[UIApplication sharedApplication] statusBarFrame].size.height : (IS_IPHONEX_SET?44.f:20.f))
- @interface UserCenterViewController1 ()
- @property(nonatomic, strong)UIWebView* webView;
- @end
- @implementation UserCenterViewController1
- - (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.
-
- //处理iphoneX屏幕尺寸
- if (State_Bar_H == 44.f) {
- //NSLog(@"iphoneX系列~");
- self.leftConstraint.constant = State_Bar_H;
- }else{
- self.leftConstraint.constant = 0;
- }
-
-
- 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]];
-
- //PS:旧版的获取手机系统语言,去掉.preferredLang.写成固定url格式的.服务器去判断,
- NSURLComponents* cmp = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"%@/float/landscape/zh/userinfo.html",XSNetwork.baseURL]];
-
-
- 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;
-
- //复制成功
- NSString *str = [NSBundle KOD_localizedStringForKey:CopySuccess];
- [XSNetwork showHudSuccess:str];
- 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{
- //未安装Facebook应用
- NSString *str = [NSBundle KOD_localizedStringForKey:NoInstallFacebookApp];
- [XSNetwork showHudSuccess:str];
- }
- }
- 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;
- }
-
- //change account
- 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"]) {
- //功能开发中
- NSString *str = [NSBundle KOD_localizedStringForKey:FunctionDeveloping];
- [XSNetwork showHudSuccess:str];
- 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
|