-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKAlertController.m
67 lines (52 loc) · 1.89 KB
/
KAlertController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// WPSAlertController.h
//
// Created by Muthupalaniappan S.
// Copyright 2015 White Peak Software. All rights reserved.
//
#import "KAlertController.h"
@interface KAlertController ()
@property (nonatomic, strong) UIWindow *alertWindow;
@end
@implementation KAlertController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[self alertWindow] setHidden:YES];
[self setAlertWindow:nil];
}
- (void)show
{
[self showAnimated:YES];
}
- (void)showAnimated:(BOOL)animated
{
UIViewController *blankViewController = [[UIViewController alloc] init];
[[blankViewController view] setBackgroundColor:[UIColor clearColor]];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setRootViewController:blankViewController];
[window setBackgroundColor:[UIColor clearColor]];
[window setWindowLevel:UIWindowLevelAlert + 1];
[window makeKeyAndVisible];
[self setAlertWindow:window];
[blankViewController presentViewController:self animated:animated completion:nil];
}
+ (void)presentOkayAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message
{
KAlertController *alertController = [KAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okayAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"OK", @"WPSKit", @"Alert button title") style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:okayAction];
[alertController show];
}
+ (void)presentOkayAlertWithError:(nullable NSError *)error
{
NSString *title = NSLocalizedStringFromTable(@"Error", @"WPSKit", @"Alert title.");
NSString *message = [error localizedDescription];
[[self class] presentOkayAlertWithTitle:title message:message];
}
@end