Skip to content

Commit

Permalink
优化APP需要重启的alert弹窗
Browse files Browse the repository at this point in the history
  • Loading branch information
boai committed Feb 14, 2019
1 parent 62cbf1b commit d5c0e3c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 44 deletions.
2 changes: 2 additions & 0 deletions DoraemonKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Pod::Spec.new do |s|
'DoraemonKit' => 'iOS/DoraemonKit/Resource/**/*'
}
ss.vendored_frameworks = 'iOS/DoraemonKit/Framework/*.framework'
s.prefix_header_contents =
'#import "DoraemonDefine.h"'
end

s.subspec 'WithLogger' do |ss|
Expand Down
7 changes: 7 additions & 0 deletions iOS/DoraemonKit/Src/Core/CommonUI/Toast/DoraemonToastUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

#import <Foundation/Foundation.h>


typedef void (^DoraemonHandleRestartActionBlock)(void);
typedef void (^DoraemonHandleRestartCancleActionBlock)(void);

@interface DoraemonToastUtil : NSObject

+ (void)showToast:(NSString *)text;

+ (void)showToast:(NSString *)text inView:(UIView *)superView;

+ (void)handleRestartActionWithVC:(UIViewController *)vc
restartBlock:(DoraemonHandleRestartActionBlock)restartBlock
cancleBlock:(DoraemonHandleRestartCancleActionBlock)cancleBlock;
@end
19 changes: 19 additions & 0 deletions iOS/DoraemonKit/Src/Core/CommonUI/Toast/DoraemonToastUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#import "UIColor+Doraemon.h"
#import "UIView+Doraemon.h"

#import "Doraemoni18NUtil.h"
#import "DoraemonCellSwitch.h"


@implementation DoraemonToastUtil

Expand All @@ -35,4 +38,20 @@ + (void)showToast:(NSString *)text inView:(UIView *)superView {

}

+ (void)handleRestartActionWithVC:(UIViewController *)vc
restartBlock:(DoraemonHandleRestartActionBlock)restartBlock
cancleBlock:(DoraemonHandleRestartCancleActionBlock)cancleBlock
{
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"该功能需要重启App才能生效") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
cancleBlock ? cancleBlock():nil;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
restartBlock ? restartBlock():nil;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[vc presentViewController:alertController animated:YES completion:nil];
}

@end
2 changes: 1 addition & 1 deletion iOS/DoraemonKit/Src/Core/Define/DoraemonDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import "UIView+Doraemon.h"
#import "UIImage+Doraemon.h"
#import "Doraemoni18NUtil.h"

#import "DoraemonToastUtil.h"

#define DoraemonScreenWidth [UIScreen mainScreen].bounds.size.width
#define DoraemonScreenHeight [UIScreen mainScreen].bounds.size.height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,12 @@ - (void)commonInit {

- (void)changeSwitchOn:(BOOL)on sender:(id)sender{
__weak typeof(self) weakSelf = self;
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"该功能需要重启App才能生效") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 weakSelf.switchView.switchView.on = !on;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[DoraemonToastUtil handleRestartActionWithVC:self restartBlock:^{
[[DoraemonCacheManager sharedInstance] saveCrashSwitch:on];
exit(0);
} cancleBlock:^{
 weakSelf.switchView.switchView.on = !on;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark DoraemonCellButtonDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,12 @@ - (BOOL)needBigTitleView{
#pragma mark -- DoraemonSwitchViewDelegate
- (void)changeSwitchOn:(BOOL)on sender:(id)sender{
__weak typeof(self) weakSelf = self;
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"该功能需要重启App才能生效") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 weakSelf.switchView.switchView.on = !on;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[DoraemonToastUtil handleRestartActionWithVC:self restartBlock:^{
[DoraemonMethodUseTimeManager sharedInstance].on = on;
exit(0);
} cancleBlock:^{
 weakSelf.switchView.switchView.on = !on;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];


}

#pragma mark -- DoraemonCellButtonDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@ - (BOOL)needBigTitleView{
#pragma mark -- DoraemonSwitchViewDelegate
- (void)changeSwitchOn:(BOOL)on sender:(id)sender{
__weak typeof(self) weakSelf = self;
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"该功能需要重启App才能生效") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 weakSelf.switchView.switchView.on = !on;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[DoraemonToastUtil handleRestartActionWithVC:self restartBlock:^{
[[DoraemonCacheManager sharedInstance] saveNSLogSwitch:on];
exit(0);
} cancleBlock:^{
 weakSelf.switchView.switchView.on = !on;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark -- DoraemonCellButtonDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,12 @@ - (BOOL)needBigTitleView{
#pragma mark -- DoraemonSwitchViewDelegate
- (void)changeSwitchOn:(BOOL)on sender:(id)sender{
__weak typeof(self) weakSelf = self;
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"该功能需要重启App才能生效") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 weakSelf.switchView.switchView.on = !on;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[DoraemonToastUtil handleRestartActionWithVC:self restartBlock:^{
[[DoraemonCacheManager sharedInstance] saveSubThreadUICheckSwitch:on];
exit(0);
} cancleBlock:^{
 weakSelf.switchView.switchView.on = !on;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark -- DoraemonCellButtonDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@ - (BOOL)needBigTitleView{
#pragma mark -- DoraemonSwitchViewDelegate
- (void)changeSwitchOn:(BOOL)on sender:(id)sender{
__weak typeof(self) weakSelf = self;
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"该功能需要重启App才能生效") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 weakSelf.switchView.switchView.on = !on;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[DoraemonToastUtil handleRestartActionWithVC:self restartBlock:^{
[[DoraemonCacheManager sharedInstance] saveLoggerSwitch:on];
exit(0);
} cancleBlock:^{
 weakSelf.switchView.switchView.on = !on;
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark -- DoraemonCellButtonDelegate
Expand Down
2 changes: 1 addition & 1 deletion iOS/DoraemonKitDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SPEC CHECKSUMS:
AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60
BSBacktraceLogger: 06b983ee93a9f87d957960e9c73d660d5966b447
CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd
DoraemonKit: 5660bbbd6abb5ff39a0ff3fb33f153d7745c5c10
DoraemonKit: 44e7daf6d961f599626ec40c25107de9ed5e2f1d
fishhook: ea19933abfe8f2f52c55fd8b6e2718467d3ebc89
PNChart: 84774d225c2126ded6c93d4dbe6ae98c3a73c2d2
UICountingLabel: 1db4e7d023e1762171eb226d6dff47a7a84f27aa
Expand Down

0 comments on commit d5c0e3c

Please sign in to comment.