question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Native Ad] Ad is misplaced at the top of the screen on iOS

See original GitHub issue

Plugin Version

google_mobile_ads: 0.12.1+1

Environment

Platform: iOS Flutter version: 2.0.5 SDK version: “>=2.12.0 ❤️.0.0”

Error description

The native ad widget is used in a SingleChildScrollView widget which scrolls horizontally. The native ad is loaded and displayed as aspected in the view but there is also an additional (unintentionally) ad that is placed at the top of the screen (see screenshot).

The app was recently migrated to null safety. This weird behavior occurred since the migration to null safety and update to Flutter 2.0. Before the migration the ad wasn’t placed at the top.

My code

class NativeAdWidget extends StatefulWidget {
  static const String ADVERTISER_VIEW = "advertiser";
  static const String BODY_VIEW = "body";
  static const String ICON_VIEW = "icon";
  static const String CTA_VIEW = "cta";
  final Size? size;
  final EdgeInsets? margin;
  final List<String> visibleViews;

  NativeAdWidget({this.size, this.margin, this.visibleViews = const []});

  @override
  _NativeAdWidgetState createState() => _NativeAdWidgetState();
}

class _NativeAdWidgetState extends State<NativeAdWidget> {
  final String nativeAdFactory = "nativeAdFactory";
  final String nativeAdUnitId = Platform.isAndroid
      ? "ca-app-pub-***"
      : "ca-app-pub-***;
  NativeAd? _nativeAd;
  BehaviorSubject<bool> _adVisibilitySubject = BehaviorSubject.seeded(false);

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (_nativeAd == null) {
      if (AppConfig.googleAdsEnabled) {
        Alerts.showiOSTrackingPermissionDialog(context).then((value) {
          _nativeAd = _createNativeAd();
          _nativeAd!.load();
        });
      }
    }
  }

  @override
  void dispose() {
    _adVisibilitySubject.close();
    if (AppConfig.googleAdsEnabled) _nativeAd?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<bool>(
        stream: _adVisibilitySubject,
        initialData: _adVisibilitySubject.value,
        builder: (ctx, snapshot) {
          if (AppConfig.googleAdsEnabled && snapshot.data!) {
            return Container(
                margin: widget.margin,
                width: widget.size?.width,
                height: widget.size?.height,
                child: AdWidget(ad: _nativeAd!));
          } else {
            return Container();
          }
        });
  }

  NativeAd _createNativeAd() {
    return NativeAd(
        adUnitId: nativeAdUnitId,
        factoryId: nativeAdFactory,
        listener: _createAdListener(),
        request: AdRequest(nonPersonalizedAds: false),
        customOptions: {
          "theme": DeviceConfig.appTheme.toString().split(".")[1],
          "visibleViews": widget.visibleViews
        });
  }

  AdListener _createAdListener() {
    return AdListener(
        onAdLoaded: (ad) => _adVisibilitySubject.add(true),
        onAdFailedToLoad: (ad, error) {
          _nativeAd?.dispose();
          _nativeAd = null;
        });
  }
}

Screenshot

screenshot

Logs

WF: _WebFilterIsActive returning: NO
WF: _userSettingsForUser mobile: {
    filterBlacklist =     (
    );
    filterWhitelist =     (
    );
    restrictWeb = 1;
    useContentFilter = 0;
    useContentFilterOverrides = 0;
    whitelistEnabled = 0;
}
WF: _WebFilterIsActive returning: NO
[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>
[ProcessSuspension] 0x1189ba2c0 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 829, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bdlukaacommented, Apr 21, 2021
0reactions
blastencommented, Apr 29, 2021

Duplicate of flutter/flutter#76097

Read more comments on GitHub >

github_iconTop Results From Across the Web

Block pop-up ads and windows in Safari - Apple Support
Block pop-up ads and windows in Safari. Learn how to block pop-up windows and handle persistent ads on your iPhone, iPad, or Mac....
Read more >
Google Advance Native Ad Display issue - ios - Stack Overflow
I am using google advance native Ad. My Ad is display successfully on simulator and device when I run from Xcode, but when...
Read more >
Full-screen native ads | iOS - Google Developers
Full-screen native ads can improve revenue and retention, either through ... the AdChoices icon is placed at the top-right corner of the ad, ......
Read more >
Guidelines for programmatic native ads using app code
This article describes the guidelines for programmatic native ads using the Android & iOS app code option. These guidelines do not apply to....
Read more >
Native advertising: what's the fuss? - The Guardian
Frédéric Filloux: The row over brand content – also known as advertorials – is a festival of fake naïveté and misplaced indignation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found