forked from SoCuul/SCInsta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.m
63 lines (52 loc) · 2.41 KB
/
Utils.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
#import <UIKit/UIKit.h>
#import "Utils.h"
#import "InstagramHeaders.h"
@implementation SCIUtils
// Colours
+ (UIColor *)SCIColour_Primary {
return [UIColor colorWithRed:0/255.0 green:152/255.0 blue:254/255.0 alpha:1];
};
// Errors
+ (NSError *)errorWithDescription:(NSString *)errorDesc {
return [self errorWithDescription:errorDesc code:1];
}
+ (NSError *)errorWithDescription:(NSString *)errorDesc code:(NSInteger)errorCode {
NSError *error = [ NSError errorWithDomain:@"com.socuul.scinsta" code:errorCode userInfo:@{ NSLocalizedDescriptionKey: errorDesc } ];
return error;
}
+ (JGProgressHUD *)showErrorHUDWithDescription:(NSString *)errorDesc {
return [self showErrorHUDWithDescription:errorDesc dismissAfterDelay:4.0];
}
+ (JGProgressHUD *)showErrorHUDWithDescription:(NSString *)errorDesc dismissAfterDelay:(CGFloat)dismissDelay {
JGProgressHUD *hud = [[JGProgressHUD alloc] init];
hud.textLabel.text = errorDesc;
hud.indicatorView = [[JGProgressHUDErrorIndicatorView alloc] init];
[hud showInView:topMostController().view];
[hud dismissAfterDelay:4.0];
return hud;
}
// Functions
+ (NSString *)IGVersionString {
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
};
+ (BOOL)isNotch {
return [[[UIApplication sharedApplication] keyWindow] safeAreaInsets].bottom > 0;
};
+ (BOOL)showConfirmation:(void(^)(void))okHandler {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:@"Are you sure?" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
okHandler();
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"No!" style:UIAlertActionStyleCancel handler:nil]];
[topMostController() presentViewController:alert animated:YES completion:nil];
return nil;
};
+ (void)prepareAlertPopoverIfNeeded:(UIAlertController*)alert inView:(UIView*)view {
if (alert.popoverPresentationController) {
// UIAlertController is a popover on iPad. Display it in the center of a view.
alert.popoverPresentationController.sourceView = view;
alert.popoverPresentationController.sourceRect = CGRectMake(view.bounds.size.width / 2.0, view.bounds.size.height / 2.0, 1.0, 1.0);
alert.popoverPresentationController.permittedArrowDirections = 0;
}
};
@end