简体   繁体   English

无法在iOS ActionExtension或ShareExtension中使用AdMob或iAd横幅广告

[英]Cannot get AdMob or iAd banner ad to work in iOS ActionExtension or ShareExtension

I cannot get either AdMob or iAd banner ads to work in an iOS ActionExtension or ShareExtension -- has anyone gotten either of these to successfully work, and if so, how? 我无法在iOS ActionExtension或ShareExtension中使用AdMob或iAd横幅广告 - 是否有人获得其中任何一项才能成功运作,如果是这样,怎么办? Both AdMob and iAd work fine in the "container" portion of the ActionExtension app (running in either the Simulator or on an actual device), but neither seem to work in the Extension. AdMob和iAd都可以在ActionExtension应用程序的“容器”部分(在模拟器中或在实际设备上运行)中正常工作,但似乎在扩展中都不起作用。 (Running in the Extension portion of the app, none of the events are fired and no ad appears but there is no sign of any errors, testing in either iOS 8 or iOS 9.) (在应用程序的扩展部分中运行,没有任何事件被触发且没有广告出现,但没有任何错误的迹象,在iOS 8或iOS 9中进行测试。)

(Note that I'm not trying to run these both together; I started with AdMob and couldn't get that to work so I replaced it with iAd, but no luck there either.) (请注意,我并不是试图将它们放在一起;我开始使用AdMob而无法使用它,所以我用iAd替换它,但也没有运气。)

If neither of these work, has anyone successfully used any ad-based component in an ActionExtension or ShareExtension? 如果这些都不起作用,是否有人在ActionExtension或ShareExtension中成功使用了任何基于广告的组件? (Unfortunately, all the functionality of this app is in the Extension portion so the only chance to monetize anything is in the Extension portion.) (不幸的是,这个应用程序的所有功能都在扩展部分,所以唯一的机会通过扩展部分获利。)

Update 1: 更新1:

I also tried AdMob Interstitial ads, but same problem. 我也试过AdMob非页内广告,但同样的问题。 Objects get instantiated, but events never get fired. 对象得到实例化,但事件永远不会被触发。

Latest iteration of code samples: 代码示例的最新迭代:

Note that while the first code samples are in C# using Xamarin.iOS, the tiny bit of information I've found via massive Googling shows similar questions (most without answers, unfortunately) in Objective-C and in Swift, so the problem seems to be in the Extension handling itself rather than in the Xamarin wrappers. 请注意,虽然第一个代码示例使用Xamarin.iOS在C#中,但我通过大量Google搜索找到的一小部分信息在Objective-C和Swift中显示了类似的问题(大多数没有答案),所以问题似乎如此在扩展处理本身而不是在Xamarin包装器中。 Also, both AdMob SDK v7.2.2 and v7.5.0 showed the same problem. 此外,AdMob SDK v7.2.2和v7.5.0都显示了同样的问题。

"Update #2" contains code samples in Objective-C -- these also fail in the exact same way. “更新#2”包含Objective-C中的代码示例 - 这些也以完全相同的方式失败。

iAd C# Version: iAd C#版本:

public partial class ActionViewController : UIViewController {
    ADBannerView _adBannerView;

    public override void ViewDidLoad () {
        base.ViewDidLoad ();

        // Hook in the iAd component
        _adBannerView = new ADBannerView (iAd.ADAdType.Banner) {
            Hidden = true
        };
        adContainerView.AddSubview (_adBannerView);

        _adBannerView.FailedToReceiveAd += (object sender, AdErrorEventArgs e) => {
            Console.WriteLine ("********** Failed to load ad: " + e.Error.LocalizedDescription);
            _adBannerView.Hidden = true;
        };

        _adBannerView.AdLoaded += (sender, args) => {
            Console.WriteLine ("********** Successfully loaded ad.");
            _adBannerView.Hidden = false;
        };
    }
}

Google AdMob C# Version: Google AdMob C#版本:

public partial class ActionViewController : UIViewController {
    const string AdmobID = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxx";
    BannerView adView;
    bool _viewOnScreen = false;

    public override void ViewDidLoad () {
        base.ViewDidLoad ();

        // === banner ad ===
        adView = new BannerView (size: AdSizeCons.Banner, origin: new CGPoint (0, 0)) {
            AdUnitID = AdmobID,
            RootViewController = this
        };

        adView.AdReceived += (object sender, EventArgs e) => {
            Console.WriteLine ("********** Banner Ad received");
            if (! _viewOnScreen) {
                adContainerView.AddSubview(adView);
                _viewOnScreen = true;
            }
        };

        adView.ReceiveAdFailed += (sender, e) => {
            Console.WriteLine ("********** BANNER AD FAILED");
        };

        Request request = Request.GetDefaultRequest();
        #if DEBUG
        request.TestDevices = new string[] { Request.GetSimulatorId().ToString() };
        #endif
        adView.LoadRequest (request);


        // === AdMob Interstitial Ads ===
        Interstitial adInterstitial = new Interstitial("ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxx");
        Request requestInterstitial = Request.GetDefaultRequest();

        adInterstitial.AdReceived += (sender, args) =>
        {
            Console.WriteLine ("********** INTERSTITAL: Successfully received ad");
        };
        adInterstitial.ReceiveAdFailed += (sender, e) => {
            Console.WriteLine ("********** INTERSTITAL: 'Receive Ad' FAILED");
        };

        #if DEBUG
        requestInterstitial.TestDevices = new string[] { Request.GetSimulatorId().ToString() };
        #endif
        adInterstitial.LoadRequest(requestInterstitial);

    }
}

Update 2: 更新2:

I also tried iAds ( ADBannerView ) in a ShareExtension in both C# and Objective-C. 我还在C#和Objective-C的ShareExtension中尝试了iAds( ADBannerView )。 Same results as above in both languages: the components are created, but no events are fired. 两种语言都具有与上述相同的结果:创建组件,但不会触发任何事件。

Also, proxying the HTTP & HTTPS traffic through another machine running Fiddler confirms that no HTTP or HTTPS request are made by the iAd component that is running in the Extension portion of the app. 此外,通过另一台运行Fiddler的计算机代理HTTP和HTTPS流量,确认在应用程序的Extension部分中运行的iAd组件没有发出HTTP或HTTPS请求。

iAd Objective-C Version (showing only iAd-related code): iAd Objective-C版本 (仅显示与iAd相关的代码):

TestViewController.h: TestViewController.h:

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@protocol ExtensionContextHolder <NSObject>
- (NSExtensionContext *)extensionContext;
@end

@interface TestViewController : UIViewController<ADBannerViewDelegate>
- (instancetype)initWithExtensionContextHolder:(id<ExtensionContextHolder>)extensionContextHolder;
@end

TestViewController.m: TestViewController.m:

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)];
    adView.delegate = self;
    [self.view addSubview:adView];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
    return YES;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"********** LOADED AN AD **********");
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"********** FAILED TO RECEIVE AN AD **********");
}

@end

Answering my own question just to close this question out for anyone else who hits this problem: Turns out that per Apple's review guidelines, review criteria 25.3 states: 回答我自己的问题,只是为了解决这个问题的其他人关闭这个问题:根据Apple的审查指南,审查标准25.3指出:

Apps hosting extensions that include marketing, advertising, or in-app purchases in their extension view will be rejected. 在其分机视图中托管包含营销,广告或应用内购买的扩展程序的应用将被拒绝。

I assumed it was a technical problem in the Extension; 我认为这是扩展中的技术问题; turns out it was, but in a much bigger way. 事实证明它是,但以更大的方式。

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

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