2021-05-25 15:38:37 -07:00
|
|
|
//
|
|
|
|
|
// MFMailComposeViewControllerFix.c
|
|
|
|
|
// App
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 5/25/21.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
#import <MessageUI/MessageUI.h>
|
2025-05-05 18:14:46 -07:00
|
|
|
#import <WebKit/WKWebView.h>
|
2021-05-25 15:38:37 -07:00
|
|
|
#import <objc/runtime.h>
|
|
|
|
|
|
|
|
|
|
@interface MFMailComposeViewController (InternalMethods)
|
|
|
|
|
+ (BOOL)canSendMailSourceAccountManagement:(NSInteger)sourceAccountManagement;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static void swizzleClassMethod(Class targetClass, SEL originalSelector, IMP replacementIMP)
|
|
|
|
|
{
|
|
|
|
|
Method originalMethod = class_getClassMethod(targetClass, originalSelector);
|
|
|
|
|
method_setImplementation(originalMethod, replacementIMP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__attribute__((constructor))
|
2023-04-19 14:33:17 -07:00
|
|
|
static void swizzleMFMailComposeViewController(void)
|
2021-05-25 15:38:37 -07:00
|
|
|
{
|
|
|
|
|
// Hacks to work around the fact that MFMailComposeViewController is broken in iOS 14+
|
|
|
|
|
swizzleClassMethod(MFMailComposeViewController.class, @selector(canSendMail), imp_implementationWithBlock(^BOOL(void) {
|
|
|
|
|
return YES;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
swizzleClassMethod(MFMailComposeViewController.class, @selector(canSendMailSourceAccountManagement:), imp_implementationWithBlock(^BOOL(NSInteger sam) {
|
|
|
|
|
return YES;
|
|
|
|
|
}));
|
|
|
|
|
}
|
2025-05-05 18:14:46 -07:00
|
|
|
|
|
|
|
|
@interface WKWebView (Hacks)
|
|
|
|
|
+ (BOOL)orig_handlesURLScheme:(NSString *)scheme;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation WKWebView (Hacks)
|
|
|
|
|
+ (BOOL)orig_handlesURLScheme:(NSString *)scheme
|
|
|
|
|
{
|
|
|
|
|
if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]) {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [self orig_handlesURLScheme:scheme];
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
__attribute__((constructor))
|
|
|
|
|
static void swizzleWebKitConfiguration(void)
|
|
|
|
|
{
|
|
|
|
|
Method origMethod = class_getClassMethod(WKWebView.class, @selector(handlesURLScheme:));
|
|
|
|
|
Method replMethod = class_getClassMethod(WKWebView.class, @selector(orig_handlesURLScheme:));
|
|
|
|
|
method_exchangeImplementations(origMethod, replMethod);
|
|
|
|
|
}
|