Xcode界面构建器未检测到Admob Framework类

编程入门 行业动态 更新时间:2024-10-15 08:24:53
本文介绍了Xcode界面构建器未检测到Admob Framework类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在尝试在我的iOS应用中实施原生Google adMob广告,并遵循admob官方教程:

我找到了一个github项目,它只是通过Cocoapoding admob框架(

几天来,我一直在挠头,寻找运气不佳的解决方案.如果您知道为什么会发生这种情况,并且高度重视您的帮助,请帮助我.

解决方案

TL; DR

将CocoaPods Pod版本降级为 7.67.0 .(-:

Podfile

pod'Google-Mobile-Ads-SDK','7.67.0'

说明

这是因为在 7.68.0 + 中 GoogleMobileAds.framework 成为了 GoogleMobileAds.xcframework -源.这意味着在框架(iOS 9)和主要目标(iOS 14.0+)之间,Objective C运行时有所不同. XCFramework 是 binary framework 的一种特殊类型,因此,在编译后手动编辑iOS版本不会有任何改变,实际上,即使您在您的 Podfile 中指定一个iOS版本,不会有所不同.

主代码在后台具有不同的,更快的Objective-C运行时,因此可以将使用不同数据结构的类跟踪到 XCFramework .例如,如果在框架中定义了类别,则即使未使用新的重写方法(在运行时),该类别也将存储在读写存储器中.另一方面,iOS 14.0+中的Objective-C运行时不会加载这些方法,直到它们用于节省RAM.对于旧的iOS版本,这是一个重大更改,因为用于索引这些类的旧数据结构不再在其中包含类别方法(在同一存储区域中)和从属逻辑(读取这些数据结构).该框架将不再起作用.方法混乱的处理方式不同,这也是 GoogleUtilities 的功能( GoogleMobileAds 的依赖项),因此这可能会引起问题.因此,即使IB自动完成功能不起作用(那里没有大问题),也不会在运行时动态找到该类.我没有提到在新运行时对方法列表表示形式的更改的更改,因为这超出了此问题的范围,但是旧方法列表在运行时仍将可用( non-重大更改).

要解决此问题,请暂时在您的 Podfile 中使用 7.67.0 版本.作为框架的最终用户,您对此无能为力,因为 podspec 将框架类型指定为 vendored_framework ,并且只能在框架的源代码中进行编辑.我试图禁用 use_frameworks ,但是无法编译.如果您可以为自己的框架编辑 podspec ,则更改为静态框架是一个可行的解决方案(带有警告).框架在构建时被链接,而不是在静态框架的加载时被链接,因此您应该能够在IB中看到框架类,但是随后您必须使框架的从属吊舱也保持静态(更多工作).更简单的等效方法是仅降级Pod,或在Podfile中禁用 use_frameworks .但是,框架具有更快的性能(链接时间),并且通常是首选的框架,这就是为什么默认情况下为CocoaPods启用了框架的原因.

我也曾建议为此漏洞制作一个新的GitHub Issue,但看起来该SDK不是开源的.也许该错误会在将来由Apple解决,或者一旦他们知道后将由Google解决,但现在这是一种解决方法.

I've been trying to implement native Google adMob ads in my iOS app and followed the admob official tutorial: developers.google/admob/ios/native/advanced

Whether I added the required admob framework manually or by CocoaPods, all the classes in the admob frameworks were not detected by the interface builder, so I could not set the Custom class of UIView to the wanted admob view classes. But weirdly I could use all the admob-related classes after the framework was imported in my swift files. See the below screenshot:

I found a github project, which did nothing but just implmented the admob native ad by Cocoapoding the admob framework (project link). I downloaded its source code and oddly the admob framework classes can be detected by interface face in this project.

I've been scratching my heads for a couple days and searching for the solution without luck. Please help me out if you have a clue why this happened and your help is highly apprecaited.

解决方案

TL;DR

Downgrade the CocoaPods pod version to 7.67.0. (-:

Podfile

pod 'Google-Mobile-Ads-SDK', '7.67.0'

Explanation

This is because GoogleMobileAds.framework became GoogleMobileAds.xcframework in 7.68.0+ - source. This means that the Objective C runtime differs between the framework (iOS 9) and the main target (iOS 14.0+). XCFrameworks are a special type of binary framework, so editing the iOS version manually after it has already been compiled won't make a difference, and in fact, even if you specify an iOS version in your Podfile it won't make a difference.

The main code has a different, faster Objective-C runtime under the hood, and so tracks classes using different data structures to the XCFramework. For example, if a category is defined in the framework, that will be stored in read-write memory even if the new overridden method isn't used (at runtime). On the other hand, the Objective-C runtime in iOS 14.0+ doesn't load these methods until they are used to save RAM. This is a breaking change for old iOS versions because the old data structures used to index these classes no longer include the category methods (in the same storage area) and dependent logic (that reads these data structures) in the framework will no longer work. Method swizzling is handled differently and this is what GoogleUtilities does as well (a dependency of GoogleMobileAds) so this can cause issues. So even if IB Autocomplete doesn't work (no big issue there), the class won't be found dynamically at runtime. I haven't mentioned changes to method list representation changes under the hood in the new runtime since that is out of scope for this question, but old method lists will still be usable at runtime (non-breaking change).

To work around this, just use the 7.67.0 version in your Podfile for now. You can't do anything else about this as an end-user of the framework, since the podspec specifies the framework type as a vendored_framework and this is only editable within the framework's source code. I tried to disable use_frameworks but that doesn't compile. If you can edit the podspec for your own frameworks, changing to a static framework is a viable solution (with caveats). The framework get linked at build time instead of load time for static frameworks so you should be able to see the framework class in IB, but then you have to make the dependent pods of the framework also static (more work). The easier equivalent is to just downgrade the pod, or disabling use_frameworks in the Podfile. However, frameworks have faster performance (linking time) and are generally preferred which is why they are enabled by default for CocoaPods.

I would also have suggested making a new GitHub Issue for this bug, but it looks like the SDK is not open-source. Maybe this bug will be resolved by Apple in the future, or by Google once they become aware of it but this is a workaround for now.

更多推荐

Xcode界面构建器未检测到Admob Framework类

本文发布于:2023-07-14 10:10:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104064.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:检测到   界面   Xcode   Admob   Framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!