8

i realised Facebook Interstitial Ad crashes with Mopub Plugin when I check the crashes on organizer

I can see backtraces on organizer.

I want to find true file to edit and fix this crash.

This is the backtrace: Backtrace

And this is the way i used

File:AdSystem.cs

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

And this is the Facebook Interstitial Adaptor for Mopub https://github.com/mopub/mopub-ios-sdk/tree/master/AdNetworkSupport/Facebook

File: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
Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
Kerem Bekman
  • 1,281
  • 2
  • 13
  • 24

1 Answers1

0

From the Official site of Mopub,

You should Pre-fetch an interstitial:

MoPub.requestInterstitialAd(interstitialAdUnit);

In this case,

MoPub.requestInterstitialAd(adUnit.key1);

Then Show the interstitial:

MoPub.showInterstitialAd (interstitialAdUnit);

In your case,

MoPub.showInterstitialAd (adUnit.key1);

So, your file AdSystem.cs should be

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

These callback handlers will help you too

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

For more details, have a look at Mopub's Official Documentation

Sagar V
  • 12,158
  • 7
  • 41
  • 68
  • Thank you for your reply. I have already pre-fetch interstitial. My code is working perfectly but some of devices crashes. I just want to fix the crash – Kerem Bekman Mar 04 '17 at 16:22
  • Can you provide 2 or 3 example devices names. – Sagar V Mar 05 '17 at 04:51
  • Iphone 6s 10.2 Iphone SE 10.2 Iphone 5s 10.2.1 Iphone 6 10.2 I think some of facebook ads crashes. If we fix FacebookInterstitialCustomEvent.m file by using try catch we can get rid of this crash? – Kerem Bekman Mar 05 '17 at 16:47