maybe can apple don't allow dlopen extra dynamic libraries , UIkitCore is Not extra framework
Post
Replies
Boosts
Views
Activity
Hi Everyone
i find the bug only happend in iOS 16.0.<iOS16.2 because ImageAnalysisutilit has bug .
if you don't need copy object from image in WKWebview you can hook the default behavior to ignore long press gesture analysis image until timeout fallback to <=iOS 15.x behavior (only can copy image without copy object from image )
https://github.com/WebKit/WebKit/blob/releases/Apple/Safari-16.1-iOS-16.1.1/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
static void hook2(void) {
Class class = objc_getClass("WKContentView");
SEL selector = sel_registerName("imageAnalysisGestureDidBegin:");
Method m = class_getInstanceMethod(class, selector);
const char *type = method_getTypeEncoding(m);
IMP newImp = imp_implementationWithBlock(^void(id self,UILongPressGestureRecognizer *ges) {
// do nothing
});
if (m == NULL || class == NULL) {
return;
}
IMP oldImp = class_replaceMethod(class, selector, newImp, type);
}
void hookStart() {
if (@available (iOS 16.0, *)) {
if (@available (iOS 16.2, *)) {
return;
} else {
hook2();
}
}
very similar another posts which crash on iOS 16
https://developer.apple.com/forums/thread/711466
Copy the code in your project to hooks default behavior
#import <dlfcn.h>
#import <UIKit/UIKit.h>
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale) {
if (size.width <= 0 || size.height <= 0) {
return;
}
static void * uikit = NULL;
static void (*realFunc)(CGSize size, BOOL opaque, CGFloat scale) = NULL;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class UIApplicationClass = NSClassFromString(@"UIApplication");
NSBundle *uikitBundle = [NSBundle bundleForClass:UIApplicationClass];
uikit = dlopen(uikitBundle.executablePath.UTF8String, RTLD_NOW);
if (uikit) {
realFunc = dlsym(uikit, "UIGraphicsBeginImageContextWithOptions");
}
});
if (realFunc) {
realFunc(size, opaque, scale);
}
}
void UIGraphicsBeginImageContext(CGSize size) {
if (size.width <= 0 || size.height <= 0) {
return;
}
static void * uikit = NULL;
static void (*realFunc)(CGSize size) = NULL;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class UIApplicationClass = NSClassFromString(@"UIApplication");
NSBundle *uikitBundle = [NSBundle bundleForClass:UIApplicationClass];
uikit = dlopen(uikitBundle.executablePath.UTF8String, RTLD_NOW);
if (uikit) {
realFunc = dlsym(uikit, "UIGraphicsBeginImageContext");
}
});
if (realFunc) {
realFunc(size);
}
}