-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTweak.xm
45 lines (34 loc) · 1.59 KB
/
Tweak.xm
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
#import <UIKit/UIKit.h>
//leftovers from classdump i used for reaearch,
// (didnt need to include it)
/* Generated by RuntimeBrowser
Platform: iOS 14.2 (18B111) arm64
Image: /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (3999.1.104)
*/
static bool kEnabled = YES;
static bool cancelActionExists= NO;
%hook UIAlertController
+ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle {
UIAlertController *originalController = %orig(title, message, preferredStyle);
if(!kEnabled) { return %orig; }
// Check if "Cancel" action is already present
for (UIAlertAction *action in [originalController actions]) {
if ((action.style==1) || ([action.title isEqualToString:@"Cancel"])) {
// 1 = UIAlertActionStyleCancel in the enumeration and 0=default. 2= destructive style
cancelActionExists = YES;
break;
}
}
// If "Cancel" action is not present, add it
if (!cancelActionExists) {
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Using cancel action style caused crash in cases where the Cancel action wasn't detected already
// Dismiss the UIAlertController here
[originalController dismissViewControllerAnimated:YES completion:nil];
}];
[originalController addAction:cancelAction];
}
return originalController;
}
%end
//Very simple short and sweet. Need to add prefs still tho.