我在将AdMob SDK集成到MoPub(在Fabric中)时遇到了困难。我通过fabric安装程序安装了MoPub。我正在使用iOS和Swift,XCode版本为7.3.1(7D1014),基本SDK iOS 9.3,项目部署目标iOS 8.0。
我能够在我的应用程序中显示MoPub测试广告,但是当通过MoPub显示AdMob广告时,我会得到运行时错误。
我找不到如何在使用Fabric MoPub安装程序时集成AdMob SDK的详细说明。只有在使用独立的MoPub SDK时添加第三方库的说明。我想保留Fabric MoPub框架。
在我让MoPub测试广告正常工作后,我按照以下步骤操作:
I added the GoogleAdMobCustomEvent.framework into the project, that came in the mopub-ios-custom-events.zip archive (found in https://dev.twitter.com/mopub/ios/mediation-fabric)
I added the GoogleMobileAds.framework (latest version from Google: v7.8.1) to the project.
In the MoPub dashboard, I created a new Order, with one Line Item and 2 ad units (banner and leaderboard) with the AdMob network.
When I run the project I get the following error:
2016-05-28 12:03:57.662 moPubTest[43756:2148130] MOPUB: Banner view (*adunit id*) loading ad with MoPub server URL: *MoPub server URL* 2016-05-28 12:04:00.909 moPubTest[43756:2148130] MOPUB: Could not find custom event class named MPGoogleAdMobBannerCustomEvent 2016-05-28 12:04:00.910 moPubTest[43756:2148130] MOPUB: Banner ad view is fetching ad network type: admob_native 2016-05-28 12:04:00.910 moPubTest[43756:2148130] MOPUB: Banner view (*adunit id*) loading ad with MoPub server URL: *MoPub server URL* 2016-05-28 12:04:00.954 moPubTest[43756:2148130] MOPUB: Banner ad view is fetching ad network type: clear 2016-05-28 12:04:00.954 moPubTest[43756:2148130] MOPUB: No ads found for ad unit: *adunit id* 2016-05-28 12:04:02.365 moPubTest[43756:2148130] MOPUB: Banner view (*adunit id*) failed. Error: Error Domain=com.mopub.iossdk Code=0 "The operation couldn’t be completed. (com.mopub.iossdk error 0.)"
我尝试过通过拖放和添加文件(选择复制文件选项),添加框架和头文件搜索路径,添加桥接头文件,更改框架头文件内部的路径等方式向项目中添加框架。在上述所有方法中,项目都可以编译通过,但在运行时仍然会收到错误消息: Could not find custom event class named MPGoogleAdMobBannerCustomEvent 有人知道可能出了什么问题吗?
谢谢!
更新: 我成功地使用CocoaPods将Fabric和MoPub框架安装到项目中,而不是使用Fabric应用程序。
Installed Fabric and Mopub via CocoaPods https://fabric.io/kits/ios/mopub/install
Instead of adding the GoogleAdMobCustomEvent.framework, I added the following Objective-C files manually to the project:
MPGoogleAdMobBannerCustomEvent.h
MPGoogleAdMobBannerCustomEvent.m
MPGoogleAdMobInterstitialCustomEvent.h
MPGoogleAdMobInterstitialCustomEvent.mThese 4 files can be found in the AdNetworkSupport folder of the ios mopub SDK git repo
Created a bridging header file with the following content:
#import <mopub_ios_sdk/MoPub-Bridging-Header.h> #import <GoogleMobileAds/GoogleMobileAds.h>
I added the GoogleMobileAds.framework (latest version from Google: v7.8.1) to the project.
Added the path to the location of GoogleMobileAds.framework/Headers in the Targets' "Search Paths" -> "Framework Search Path"
理论上,您也可以通过CocoaPods安装MoPub的自定义事件,但由于一个错误,目前不可能实现。(请参见https://stackoverflow.com/a/36830967/6394927)
希望这能帮助未来的某个人。