Closed FKV587 closed 2 years ago
App 启动时,会试图通过 QMUIRuntime getProjectImageHeader() 函数获取当前 App 的所有头文件(不包含 App 引入的其他第三方 framework),该函数的实现有问题导致某些情况下无法正确获取,新版本会修复该 bug,在此之前可使用以下代码临时替换本地 QMUI 里的代码:
static const headerType *getProjectImageHeader() {
const uint32_t imageCount = _dyld_image_count();
NSString *executablePath = NSBundle.mainBundle.executablePath;
if (!executablePath) return nil;
const headerType *target_image_header = 0;
for (uint32_t i = 0; i < imageCount; i++) {
const char *image_name = _dyld_get_image_name(i);// name 是一串完整的文件路径,以 image 名结尾
NSString *imagePath = [NSString stringWithUTF8String:image_name];
if ([imagePath isEqualToString:executablePath]) {
target_image_header = (headerType *)_dyld_get_image_header(i);
break;
}
}
return target_image_header;
}
注意,XCTest 运行时无法加载配置表,且 getProjectImageHeader()
得到的也为 nil,也会命中 QMUIConfiguration.m 里的检测,所以 QMUIConfiguration.m applyInitialTemplate 方法会屏蔽 XCTest 的场景。
测试过以 .a 形式(CocoaPods 里屏蔽掉 use_frameworks!
)引入的 QMUI,也能正常获取 classes。
iOS18会触发这行断言,查找对比后发现DEBUG模式下,二进制不包含__objc_classlist,而会在另一产物xxxx.debug.dylib里
设备:iPhone 8 系统:iOS 14.1 Xcode 版本:13.0 QMUI iOS 版本:4.3.0 qmui_getProjectClassList 获取类数量为0 objc_getClassList 系统获取类数量为36939![image](https://user-images.githubusercontent.com/8774976/139395633-d14e1cd0-843f-47df-8bb2-376daf311a82.png)