Created
June 21, 2019 09:18
-
-
Save 1ookup/33fa5cd221ca10818a43fff8666f33e4 to your computer and use it in GitHub Desktop.
使用XUI 全局设置管理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SettingManager.h | |
// ProtocolRecord | |
// | |
#import <Foundation/Foundation.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface SettingManager : NSObject | |
+(instancetype) shareInstance; | |
-(void)addManagerBtn; | |
-(void)initSetting; | |
@end | |
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SettingManager.m | |
// ProtocolRecord | |
// | |
#import <UIKit/UIKit.h> | |
#import <JhtFloatingBall/JhtFloatingBall.h> | |
#import <XUI/XUI.h> | |
#import "SettingManager.h" | |
@interface SettingManager () <JhtFloatingBallDelegate> | |
@property (nonatomic, strong) JhtFloatingBall *btn; | |
@property (nonatomic, strong) NSString *interfacePath; | |
@end | |
@implementation SettingManager | |
static SettingManager* _instance = nil; | |
+(instancetype) shareInstance | |
{ | |
static dispatch_once_t onceToken ; | |
dispatch_once(&onceToken, ^{ | |
_instance = [[self alloc] init] ; | |
[_instance initSetting]; | |
}) ; | |
return _instance ; | |
} | |
-(void)initSetting | |
{ | |
self.interfacePath = @"/var/mobile/Library/Preferences/xxxxxx.json"; | |
NSUserDefaults* userDefault = [NSUserDefaults standardUserDefaults]; | |
if(![userDefault objectForKey:@"GlobalEnabled"]) { | |
[userDefault setObject:@0 forKey:@"GlobalEnabled"]; | |
[userDefault setObject:@"http://www.xxx.com/api" forKey:@"APIAddr"]; | |
[userDefault synchronize]; | |
} | |
////[[NSUserDefaults standardUserDefaults] objectForKey:@"GlobalEnabled"] | |
} | |
-(void)addManagerBtn | |
{ | |
CGRect b = [[UIScreen mainScreen] bounds]; | |
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://www.easyicon.net/download/png/1232091/128/"]]; | |
UIImage *img = [UIImage imageWithData:data]; | |
JhtFloatingBall* btn = [[JhtFloatingBall alloc] | |
initWithFrame:CGRectMake(b.size.width-58-2, b.size.height - 120, 58, 58)]; | |
btn.image = img; | |
btn.stayAlpha = 0; | |
btn.delegate = self; | |
btn.stayBlock = ^(CGRect frame) { | |
NSLog(@"touchesEndBlock => %@", NSStringFromCGRect(frame)); | |
}; | |
btn.touchesMovedBlock = ^(CGRect frame) { | |
NSLog(@"touchesMovedBlock => %@", NSStringFromCGRect(frame)); | |
}; | |
[[UIApplication sharedApplication].keyWindow addSubview:btn]; | |
} | |
#pragma mark - JhtFloatingBallDelegate | |
- (void)tapFloatingBall { | |
NSString* bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]; | |
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"配置" | |
message:@"配置" preferredStyle:UIAlertControllerStyleActionSheet]; | |
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"全局配置" | |
style:UIAlertActionStyleDefault | |
handler:^(UIAlertAction * _Nonnull action) { | |
NSString *xuiPath = [NSString stringWithFormat:@"%@", self.interfacePath]; | |
[XUIListViewController presentFromTopViewControllerWithPath:xuiPath]; | |
}]; | |
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { | |
NSLog(@"取消"); | |
}]; | |
[actionSheet addAction:action1]; | |
//[actionSheet addAction:action2]; | |
[actionSheet addAction:action3]; | |
UIViewController* vcc = [self getCurrentVC]; | |
[vcc presentViewController:actionSheet animated:YES completion:nil]; | |
} | |
- (UIViewController *)getCurrentVC | |
{ | |
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; | |
UIViewController *currentVC = [self getCurrentVCFrom:rootViewController]; | |
return currentVC; | |
} | |
- (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC | |
{ | |
UIViewController *currentVC; | |
if ([rootVC presentedViewController]) { | |
// 视图是被presented出来的 | |
rootVC = [rootVC presentedViewController]; | |
} | |
if ([rootVC isKindOfClass:[UITabBarController class]]) { | |
// 根视图为UITabBarController | |
currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]]; | |
} else if ([rootVC isKindOfClass:[UINavigationController class]]){ | |
// 根视图为UINavigationController | |
currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]]; | |
} else { | |
// 根视图为非导航类 | |
currentVC = rootVC; | |
} | |
return currentVC; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title":"配置", | |
"theme":{ | |
"navigationTitleColor": "#000000", | |
"navigationBarColor": "#FFFFFF" | |
}, | |
"items":[ | |
{ | |
"label":"功能", | |
"cell":"Group", | |
"footerText":"Author: xxxxxx" | |
}, | |
{ | |
"cell":"Switch", | |
"label":"总开关", | |
"key":"GlobalEnabled", | |
"default":false | |
}, | |
{ | |
"cell":"TextField", | |
"label":"上报地址", | |
"key":"APIAddr", | |
"default": "http://www.xxx.com/api" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment