Facebook上的Interstitial广告崩溃Mopub插件在Unity上

时间:2017-02-23 15:41:05

标签: ios unity3d mopub

当我检查组织者的崩溃时,我意识到Facebook插页式广告与Mopub插件崩溃

我可以看到组织者的回溯。

我想找到真正的文件进行编辑并修复此崩溃。

这是回溯: Backtrace

这就是我用的方式

文件:AdSystem.cs

try {
    MoPub.showInterstitialAd(adUnit.key1);
}
catch(Exception e) {
}

这是适用于Mopub的Facebook非页内适配器 https://github.com/mopub/mopub-ios-sdk/tree/master/AdNetworkSupport/Facebook

文件:FacebookInterstitialCustomEvent.m

//
//  FacebookInterstitialCustomEvent.m
//  MoPub
//
//  Copyright (c) 2014 MoPub. All rights reserved.
//

#import <FBAudienceNetwork/FBAudienceNetwork.h>
#import "FacebookInterstitialCustomEvent.h"

#import "MPInstanceProvider.h"
#import "MPLogging.h"

@interface MPInstanceProvider (FacebookInterstitials)

- (FBInterstitialAd *)buildFBInterstitialAdWithPlacementID:(NSString *)placementID
                                                  delegate:(id<FBInterstitialAdDelegate>)delegate;

@end

@implementation MPInstanceProvider (FacebookInterstitials)

- (FBInterstitialAd *)buildFBInterstitialAdWithPlacementID:(NSString *)placementID
                                                  delegate:(id<FBInterstitialAdDelegate>)delegate
{
    FBInterstitialAd *interstitialAd = [[FBInterstitialAd alloc] initWithPlacementID:placementID];
    interstitialAd.delegate = delegate;
    return interstitialAd;
}

@end

@interface FacebookInterstitialCustomEvent () <FBInterstitialAdDelegate>

@property (nonatomic, strong) FBInterstitialAd *fbInterstitialAd;

@end

@implementation FacebookInterstitialCustomEvent

- (void)requestInterstitialWithCustomEventInfo:(NSDictionary *)info
{
    if (![info objectForKey:@"placement_id"]) {
        MPLogError(@"Placement ID is required for Facebook interstitial ad");
        [self.delegate interstitialCustomEvent:self didFailToLoadAdWithError:nil];
        return;
    }

    MPLogInfo(@"Requesting Facebook interstitial ad");

    self.fbInterstitialAd =
    [[MPInstanceProvider sharedProvider] buildFBInterstitialAdWithPlacementID:[info objectForKey:@"placement_id"]
                                                                     delegate:self];

    [self.fbInterstitialAd loadAd];
}

- (void)showInterstitialFromRootViewController:(UIViewController *)controller {
    if (!self.fbInterstitialAd || !self.fbInterstitialAd.isAdValid) {
        MPLogError(@"Facebook interstitial ad was not loaded");
        [self.delegate interstitialCustomEventDidExpire:self];
    } else {
        MPLogInfo(@"Facebook interstitial ad will be presented");
        [self.delegate interstitialCustomEventWillAppear:self];
        [self.fbInterstitialAd showAdFromRootViewController:controller];
        MPLogInfo(@"Facebook interstitial ad was presented");
        [self.delegate interstitialCustomEventDidAppear:self];
    }
}

- (void)dealloc
{
    _fbInterstitialAd.delegate = nil;
}

#pragma mark FBInterstitialAdDelegate methods

- (void)interstitialAdDidLoad:(FBInterstitialAd *)interstitialAd
{
    MPLogInfo(@"Facebook intersitital ad was loaded. Can present now");
    [self.delegate interstitialCustomEvent:self didLoadAd:interstitialAd];
}

- (void)interstitialAd:(FBInterstitialAd *)interstitialAd didFailWithError:(NSError *)error
{
    MPLogInfo(@"Facebook intersitital ad failed to load with error: %@", error.description);
    [self.delegate interstitialCustomEvent:self didFailToLoadAdWithError:nil];
}

- (void)interstitialAdDidClick:(FBInterstitialAd *)interstitialAd
{
    MPLogInfo(@"Facebook interstitial ad was clicked");
    [self.delegate interstitialCustomEventDidReceiveTapEvent:self];
}

- (void)interstitialAdDidClose:(FBInterstitialAd *)interstitialAd
{
    MPLogInfo(@"Facebook interstitial ad was closed");
    [self.delegate interstitialCustomEventDidDisappear:self];
}

- (void)interstitialAdWillClose:(FBInterstitialAd *)interstitialAd
{
    MPLogInfo(@"Facebook interstitial ad will close");
    [self.delegate interstitialCustomEventWillDisappear:self];
}

@end

1 个答案:

答案 0 :(得分:0)

来自Mopub的官方网站,

您应该预先获取插页式广告:

MoPub.requestInterstitialAd(interstitialAdUnit);

在这种情况下,

MoPub.requestInterstitialAd(adUnit.key1);

然后显示插页式广告:

MoPub.showInterstitialAd (interstitialAdUnit);

在你的情况下,

MoPub.showInterstitialAd (adUnit.key1);

因此,您的文件AdSystem.cs应为

try {
    MoPub.requestInterstitialAd(adUnit.key1);
    MoPub.showInterstitialAd(adUnit.key1);
}
catch(Exception e) {
}

这些回调处理程序也会对您有所帮助

void onInterstitialLoaded (string adUnitId)
void onInterstitialFailed (string errorMsg)
void onInterstitialDismissed (string adUnitId)
void interstitialDidExpire (string adUnitId)
void onInterstitialShown (string adUnitId)
void onInterstitialClicked (string adUnitId)

有关详细信息,请查看Mopub's Official Documentation

相关问题