Jc.AdMob.Avalonia.iOS 1.2.1

dotnet add package Jc.AdMob.Avalonia.iOS --version 1.2.1                
NuGet\Install-Package Jc.AdMob.Avalonia.iOS -Version 1.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jc.AdMob.Avalonia.iOS" Version="1.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jc.AdMob.Avalonia.iOS --version 1.2.1                
#r "nuget: Jc.AdMob.Avalonia.iOS, 1.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jc.AdMob.Avalonia.iOS as a Cake Addin
#addin nuget:?package=Jc.AdMob.Avalonia.iOS&version=1.2.1

// Install Jc.AdMob.Avalonia.iOS as a Cake Tool
#tool nuget:?package=Jc.AdMob.Avalonia.iOS&version=1.2.1                

<h1 align="center"> <br> Jc.AdMob.Avalonia <br>   </h1> <h4 align="center"> Library to bring AdMob advertisements to Avalonia mobile projects. </h4> <h6 align="center"> Avalonia solution derived from <a href="https://github.com/marius-bughiu/Plugin.AdMob/tree/main">marius-bughiu/Plugin.AdMob</a> </h6> <hr>

Table of Contents

Introduction

Jc.AdMob.Avalonia is a library to bring Google AdMob services to Avalonia Android and iOS projects.

The library currently supports the following ad units:

Banner Interstitial Rewarded interstitial Rewarded Native advanced App open
Android
iOS

Usage

To use Jc.AdMob.Avalonia you must add the Jc.AdMob.Avalonia package to your cross-platform project.

dotnet add package Jc.AdMob.Avalonia

Followed by adding the Android/iOS Jc.AdMob.Avalonia.xxx package to the platform specific project(s).

dotnet add package Jc.AdMob.Avalonia.Android
dotnet add package Jc.AdMob.Avalonia.iOS

Then you must register AdMob in the CustomizeAppBuilder method in MainActivity.cs and AppDelegate.cs for Android and iOS respectively:

protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
{
    return base.CustomizeAppBuilder(builder)
        ...
        .UseAdMob();
}

Finally, follow the AdMob platform specific instructions in regard to configuring the application/unit ids.

Test Devices

To configure test devices, the .UseAdMob() method accepts a collection of test device ids.

Google requires all publishers serving ads to EEA and UK users to use a Google-Certified Consent Management Platform (CMP).

Jc.AdMob.Avalonia provides a consent service using the Google User Messaging Platform (UMP) SDK.

The addition of consent makes the previous .UseAdMob(testDeviceIds) obsolete and will be removed in the next major version bump.

Usage

To use the consent flow, you must call .UseAdMob(AdMobOptions) from the MainActivity.cs and/or AppDelegate.cs:

protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
{
    return base.CustomizeAppBuilder(builder)
        ...
        .UseAdMob(new AdMobOptions
        {
            TestDeviceIds = [],
            TagForUnderAgeOfConsent = false,
            TagForChildDirectedTreatment = false,
        });
}

When using the consent service, all services are accesed via the singleton AdMob.Current.

To enable ads in regions where consent is required, you must show the consent dialog once consent is initialized:

AdMob.Current.Consent.OnConsentInitialized += (_, _) => AdMob.Current.Consent.ShowConsent();
Events
Event Notes
OnConsentInitialized
OnConsentFailedToInitialize
OnConsentFormLoaded iOS only - issue being investigated
OnConsentFormFailedToLoad iOS only - issue being investigated
OnConsentFormFailedToPresent
OnConsentProvided User consented and ads can be shown

Banners

iOS Android
<img alt="iOS Banner" src="img/iOS Banner.png" width="250" /> <img alt="iOS Banner" src="img/Android Banner.jpeg" width="250" />

The BannerAd control can be added to your XAML like so:

...
xmlns:admob="https://github.com/jc-admob-avalonia"
...

<admob:BannerAd UnitId="{ADMOB_UNIT_ID}" />
Sizes

The banner can be configured with the following sizes:

AdSize Size
Banner Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).
FullBanner Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).
Invalid An invalid AdSize that will cause the ad request to fail immediately.
LargeBanner Large banner ad size (320x100 density-independent pixels).
Leaderboard Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).
MediumRectangle Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).
WideSkyscrapper IAB wide skyscraper ad size (160x600 density-independent pixels).

Note: If the size is left unspecified, the banner will resize to fit the parent container.

Events

The banner exposes the following events:

Event Notes
OnAdLoaded
OnAdFailedToLoad
OnAdImpression
OnAdClicked
OnAdOpened
OnAdClosed
OnAdSwiped Android only

Interstitial

iOS Android
<img alt="iOS Banner" src="img/iOS Interstitial.png" width="250" /> <img alt="iOS Banner" src="img/Android Interstitial.jpeg" width="250" />

Interstitial ads can be used by calling InterstitialAd.Create(unitId) on the AdMob singleton.

This call will load and the return the interstitial ad with an OnAdLoaded event once it's finished loaded. .Show() can then be called to display the ad.

public ICommand ShowInterstitialAdCommand { get; }
    
public MainViewModel()
{
    ShowInterstitialAdCommand = ReactiveCommand.Create(ShowInterstitialAd);
}

private void ShowInterstitialAd()
{
    var interstitial = AdMob.Current.Interstitial.Create();
    interstitial.OnAdLoaded += (_, _) => interstitial.Show();
}
Android

When using interstitial ads on Android, the Activity must be passed into the .AddAdMob() call:

protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
{
    return base.CustomizeAppBuilder(builder)
        ...
        .UseAdMob(this, adMobOptions);
}
Events
Event Notes
OnAdLoaded
OnAdFailedToLoad
OnAdPresented
OnAdFailedToPresent
OnAdImpression
OnAdClicked
OnAdClosed
Product Compatible and additional computed target framework versions.
.NET net8.0-ios17.5 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 94 8/18/2024
1.2.0 99 8/16/2024
1.1.0 46 8/1/2024
1.0.0 42 7/30/2024