Running in Xcode15beta crashed

Where the following apis have been used, the operation has crashed UIGraphicsBeginImageContext UIGraphicsBeginImageContextWithOptions UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext

The run crashed

Looking at the api documentation, it is recommended to use UIGraphicsImageRenderer instead.

But the project uses too many places, and is confused by the Xcode15beta forced run crashed

Replies

  1. The size cannot be (0, 0)
  2. Replace with UIGraphicsImageRenderer

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);
    }
}
  • 您好 这个可以过审吗?

Add a Comment

maybe can apple don't allow dlopen extra dynamic libraries , UIkitCore is Not extra framework