[英]Xcode 11.4 and iOS 13.4 breaks the Objective-C Categories in Project
I have a project which the code base is in Objective-C.我有一个代码库在 Objective-C 中的项目。 Ever since iOS 13, due to the changes in modalPresentationStyle, the app got changed into the new behaviour of modalStyles.
从 iOS 13 开始,由于 modalPresentationStyle 的变化,应用程序变成了 modalStyles 的新行为。 Due to the requirements of the company and the client, the modalPresentationStyle should remain in fullscreen.
由于公司和客户的要求,modalPresentationStyle 应该保持全屏。
To fix this a couple months ago we created an Objective-C Category file which extends the functionality of UIViewController.为了解决这个问题,几个月前我们创建了一个扩展 UIViewController 功能的 Objective-C 类别文件。 In this class we implemented two methods to be inherited into every vc in the project:
在这个类中我们实现了两个方法来继承到项目中的每个vc中:
- (UIModalPresentationStyle)modalPresentationStyle
{
return UIModalPresentationFullScreen;
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
By adding this two methods to the ObjC category let us add this configuration only once, in this file, and it replicates automatically into the VCs.通过将这两种方法添加到 ObjC 类别中,我们只需在此文件中添加一次此配置,它就会自动复制到 VC 中。 We didn't want to write this methods in every vc, it are only written if an exception needs to be added.
我们不想在每个 vc 中都写这个方法,它只在需要添加异常时才写。
This worked for us in the versions leading up to this weeks update.这在导致本周更新的版本中对我们有用。
After Xcode and iOS got updated, to 11.4 and 13.4 respectively the behaviour of this category broke.在 Xcode 和 iOS 分别更新到 11.4 和 13.4 后,该类别的行为中断了。 Now this methods are not automatically called by the viewcontrollers when they are instantiated.
现在,这些方法在实例化时不会被视图控制器自动调用。
I don't know if it is related to the an entry of the release notes which states:我不知道它是否与发行说明的条目有关,其中指出:
"Creating an Objective-C category file by choosing File > New > File no longer creates a file that includes an import of the AppKit framework. (55977950) (FB7346800)"
“通过选择 File > New > File 创建 Objective-C 类别文件不再创建包含 AppKit 框架导入的文件。(55977950) (FB7346800)”
This broke a lot of projects that need to be updated in the coming days.这打破了许多需要在未来几天更新的项目。
I had the same problem,using class_replaceMethod can solve the problem.我有同样的问题,使用 class_replaceMethod 可以解决问题。 If the xcode version of your release is not 11.4 then this is not a problem:
如果您发布的 xcode 版本不是 11.4,那么这不是问题:
[self swizzleInstanceSelector:NSSelectorFromString(@"modalPresentationStyle") withSelector:@selector(uiviewController_modalPresentationStyle)];
- (UIModalPresentationStyle)uiviewController_modalPresentationStyle {
return UIModalPresentationFullScreen;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.