繁体   English   中英

Xcode 11.4 和 iOS 13.4 打破了项目中的 Objective-C 类别

[英]Xcode 11.4 and iOS 13.4 breaks the Objective-C Categories in Project

我有一个代码库在 Objective-C 中的项目。 从 iOS 13 开始,由于 modalPresentationStyle 的变化,应用程序变成了 modalStyles 的新行为。 由于公司和客户的要求,modalPresentationStyle 应该保持全屏。

为了解决这个问题,几个月前我们创建了一个扩展 UIViewController 功能的 Objective-C 类别文件。 在这个类中我们实现了两个方法来继承到项目中的每个vc中:

- (UIModalPresentationStyle)modalPresentationStyle
{
    return UIModalPresentationFullScreen;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

通过将这两种方法添加到 ObjC 类别中,我们只需在此文件中添加一次此配置,它就会自动复制到 VC 中。 我们不想在每个 vc 中都写这个方法,它只在需要添加异常时才写。

这在导致本周更新的版本中对我们有用。

在 Xcode 和 iOS 分别更新到 11.4 和 13.4 后,该类别的行为中断了。 现在,这些方法在实例化时不会被视图控制器自动调用。

我不知道它是否与发行说明的条目有关,其中指出:

“通过选择 File > New > File 创建 Objective-C 类别文件不再创建包含 AppKit 框架导入的文件。(55977950) (FB7346800)”

这打破了许多需要在未来几天更新的项目。

我有同样的问题,使用 class_replaceMethod 可以解决问题。 如果您发布的 xcode 版本不是 11.4,那么这不是问题:

[self swizzleInstanceSelector:NSSelectorFromString(@"modalPresentationStyle") withSelector:@selector(uiviewController_modalPresentationStyle)];
- (UIModalPresentationStyle)uiviewController_modalPresentationStyle {
    return UIModalPresentationFullScreen;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM