### Fix XML Tag Mismatch in UserMessagingPlatform Targets
Source: https://hightouchinnovation.com/MMTAdmobGuide
To resolve the '_GoogleUserMessagingPlatformAssemblyName' start tag mismatch error in the UserMessagingPlatform targets file, replace the specified line with the corrected version.
```xml
<_GoogleUserMessagingPlatformAssemblyName> Google.UserMessagingPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
```
```xml
<_GoogleUserMessagingPlatformAssemblyName>Google.UserMessagingPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
```
--------------------------------
### Set Global Personalized Ads Property
Source: https://hightouchinnovation.com/MMTAdmobGuide
Example of setting the UserPersonalizedAds global property to control ad personalization, useful for GDPR compliance.
```csharp
CrossMauiMTAdmob.Current.UserPersonalizedAds = true;
```
--------------------------------
### Get Number of Rewarded Ads Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieve the count of currently loaded rewarded ads. This functionality is available in the licensed version of the plugin.
```csharp
int numberOfRewarded = CrossMauiMTAdmob.Current.GetNumberOfRewardedLoaded();
```
--------------------------------
### Get Number of Interstitials Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieves the count of currently loaded interstitial ads.
```APIDOC
## GetNumberOfInterstitialsLoaded
### Description
Gets the number of interstitials loaded.
### Method
```csharp
int GetNumberOfInterstitialsLoaded();
```
### Example
```csharp
int numberOfInterstitials = CrossMauiMTAdmob.Current.GetNumberOfInterstitialsLoaded();
```
### Note
Only the licensed version allows loading multiple interstitials.
```
--------------------------------
### Get Number of Rewarded Interstitial Ads Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieves the count of currently loaded rewarded interstitial ads.
```APIDOC
## Getting the Number of Rewarded Interstitial Ads Loaded
To get the number of rewarded interstitial ads loaded, use the `GetNumberOfRewardedInterstitialsLoaded` method:
```
int GetNumberOfRewardedInterstitialsLoaded();
```
```
--------------------------------
### Get Number of Interstitials Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieve the count of currently loaded interstitial ads using `GetNumberOfInterstitialsLoaded`. This is primarily useful in the licensed version which supports multiple ads.
```csharp
int GetNumberOfInterstitialsLoaded();
```
```csharp
int numberOfInterstitials = CrossMauiMTAdmob.Current.GetNumberOfInterstitialsLoaded();
```
--------------------------------
### Get Number of Rewarded Interstitials Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieve the count of currently loaded rewarded interstitial ads. This method is particularly useful in the licensed version which supports loading multiple ads.
```csharp
int numberOfRewardedInterstitials = CrossMauiMTAdmob.Current.GetNumberOfRewardedInterstitialsLoaded();
```
--------------------------------
### General Methods
Source: https://hightouchinnovation.com/MMTAdmobGuide
General methods for initializing and controlling ad settings.
```APIDOC
## General Methods
### Init
Initializes the AdMob plugin.
### SetAppMuted
Sets the muted state for the application's audio.
### SetAppVolume
Sets the volume level for the application's audio.
```
--------------------------------
### Initialize MAUI AdMob Plugin
Source: https://hightouchinnovation.com/MMTAdmobGuide
Add this to your MauiProgram class to enable the AdMob plugin.
```csharp
.UseMauiMTAdmob()
```
--------------------------------
### Android Initialization
Source: https://hightouchinnovation.com/MMTAdmobGuide
Signature for initializing the AdMob plugin on Android.
```APIDOC
## Android Initialization
### Method Signature
```csharp
void Init(MauiAppCompatActivity activity, string appId, string license = null, string nativeAdsId = null, string openAdsId = null, bool enableOpenAds = false, bool tagForUnderAgeOfConsent = false, string testDeviceId = null, bool forceTesting = false, DebugGeography geography = DebugGeography.DEBUG_GEOGRAPHY_DISABLED, bool initialiseConsentAtStartup = true, bool debugMode = false);
```
```
--------------------------------
### iOS Init Method Signature
Source: https://hightouchinnovation.com/MMTAdmobGuide
Signature for initializing the AdMob plugin on iOS. Many parameters are optional and have default values.
```csharp
void Init(string license = null, string nativeAdsId = null, string openAdsId = null, bool enableOpenAds = false, bool tagForUnderAgeOfConsent = false, string testDeviceId = null, DebugGeography geography = DebugGeography.DEBUG_GEOGRAPHY_DISABLED, bool initialiseConsentAtStartup = true, bool debugMode = false);
```
--------------------------------
### App Open Ads Initialization and Lifecycle
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initializes and manages App Open Ads, which are available in the licensed version of the plugin. Includes platform-specific resume handling.
```APIDOC
## App Open Ads
App Open Ads are only available in the licensed version of the plugin.
To enable the App Open Ads in you apps, you can buy the license here.
The plugin provides functionality to load and display App Open ads in an Android and iOS application, while handling ad loading callbacks and error handling.
To initialize the Open Ads in your app, you need to set the corresponding variable _enableOpenAds_ in
`CrossMauiMTAdmob.Current.Init(...)`
In the same Init, you also need to pass your Open App Id in _openAdsId._
To load and show your Open Ads when the app starts or goes into foreground, you need the following code:
## Android
`protected override void OnResume()`
`{
base.OnResume();
CrossMauiMTAdmob.Current.OnResume();
}`
## iOS
` public override void OnActivated(UIApplication application)`
`{
base.OnActivated(application);
CrossMauiMTAdmob.Current.OnResume();
}`
```
--------------------------------
### Initialize Plugin
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initializes the MTAdMob plugin with various configuration options. This method is available for both Android and iOS, but specific manifest/plist configurations are required.
```APIDOC
## Initialize Plugin
### Description
Initializes the MTAdMob plugin with various configuration options. This method is available for both Android and iOS, but specific manifest/plist configurations are required.
### Parameters
#### Path Parameters
- **activity** (`MauiAppCompatActivity`) - Required - The activity to initialize the plugin with.
- **appId** (`string`) - Required - The AdMob app ID.
- **license** (`string`) - Optional - The license key.
- **openAdsId** (`string`) - Optional - The open ads ID.
- **nativeAdsId** (`string`) - Optional - The native ads ID.
- **enableOpenAds** (`bool`) - Optional - True to enable open ads, false otherwise. Default: `false`.
- **tagForUnderAgeOfConsent** (`bool`) - Optional - True to tag for under age of consent, false otherwise. Default: `false`.
- **testDeviceId** (`string`) - Optional - The test device ID.
- **forceTesting** (`bool`) - Optional - True to force testing, false otherwise. Default: `false`.
- **geography** (`DebugGeography`) - Optional - The debug geography. Default: `DebugGeography.DEBUG_GEOGRAPHY_DISABLED`.
- **initialiseConsentAtStartup** (`bool`) - Optional - True to initialize consent at startup, false otherwise. Default: `true`.
- **debugMode** (`bool`) - Optional - if True, will show debug console messages to help you during development. Default: `false`.
### iOS Method Signature
```csharp
void Init(string license = null, string nativeAdsId = null, string openAdsId = null, bool enableOpenAds = false, bool tagForUnderAgeOfConsent = false, string testDeviceId = null, DebugGeography geography = DebugGeography.DEBUG_GEOGRAPHY_DISABLED, bool initialiseConsentAtStartup = true, bool debugMode = false);
```
### Android Manifest Configuration
Add your AdMob APPLICATION_ID to your AppManifest:
```xml
```
### iOS Info.plist Configuration
Edit your info.plist adding these Keys:
```xml
GADApplicationIdentifier
YOUR APPLICATION ID
GADIsAdManagerApp
```
```
--------------------------------
### Load Native Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initiate the loading process for a native ad. Ensure that the necessary ad unit IDs are configured for native ads.
```csharp
CrossMauiMTAdmob.Current.LoadNativeAd();
```
--------------------------------
### Load Native Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initiates the loading process for a native ad.
```APIDOC
# IMTAdmob Native Ads Documentation
This documentation provides an overview of how to use native ads with the `CrossMauiMTAdmob.Current` interface.
## Loading a Native Ad
To load a native ad, use the `LoadNativeAd` method:
```
void LoadNativeAd();
```
```
--------------------------------
### MAUI MTAdView Code Initialization
Source: https://hightouchinnovation.com/MMTAdmobGuide
Instantiating an MTAdView control programmatically in C#.
```csharp
MTAdView ads = new MTAdView();
```
--------------------------------
### Initialize AdMob Plugin for Android
Source: https://hightouchinnovation.com/MMTAdmobGuide
Call the Init method in your Android platform code to initialize the AdMob plugin. This method requires the activity, app ID, and can optionally include license, native ads ID, open ads ID, and other configuration parameters.
```csharp
void Init(MauiAppCompatActivity activity, string appId, string license = null, string nativeAdsId = null, string openAdsId = null, bool enableOpenAds = false, bool tagForUnderAgeOfConsent = false, string testDeviceId = null, bool forceTesting = false, DebugGeography geography = DebugGeography.DEBUG_GEOGRAPHY_DISABLED, bool initialiseConsentAtStartup = true, bool debugMode = false);
```
--------------------------------
### Import Xamarin.AndroidX.Lifecycle.LiveData for .NET 7
Source: https://hightouchinnovation.com/MMTAdmobGuide
For .NET 7 projects experiencing package downgrade errors with Xamarin.AndroidX.Lifecycle.LiveData, directly reference the package with the specified version.
```xml
Xamarin.AndroidX.Lifecycle.LiveData Version="2.6.2.3"
```
--------------------------------
### Show Native Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Shows a previously loaded native ad.
```APIDOC
## Show Native Ad
### Description
Shows a previously loaded native ad.
### Method Signature
```csharp
void ShowNativeAd();
```
### Usage Example
```csharp
myNativeAds.ShowNativeAd();
```
```
--------------------------------
### Request User Consent Form
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initiates the process to show the Google EU User Consent form to the user. This is typically called during app initialization.
```csharp
void InitialiseAndShowConsentForm();
```
```csharp
CrossMauiMTAdmob.Current.InitialiseAndShowConsentForm();
```
--------------------------------
### Show Native Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Call this method to display a previously loaded native ad.
```csharp
void ShowNativeAd();
```
```csharp
myNativeAds.ShowNativeAd();
```
--------------------------------
### Handle Native Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Subscribe to these events to manage the lifecycle of native ads, including loading, opening, closing, and errors.
```csharp
CrossMauiMTAdmob.Current.OnNativeAdLoaded += (sender, args) => {
// Handle native ad loaded
};
CrossMauiMTAdmob.Current.OnNativeAdOpened += (sender, args) => {
// Handle native ad opened
};
CrossMauiMTAdmob.Current.OnNativeAdClosed += (sender, args) => {
// Handle native ad closed
};
CrossMauiMTAdmob.Current.OnNativeAdFailedToLoad += (sender, args) => {
// Handle native ad failed to load
};
CrossMauiMTAdmob.Current.OnNativeAdFailedToShow += (sender, args) => {
// Handle native ad failed to show
};
CrossMauiMTAdmob.Current.OnNativeAdImpression += (sender, args) => {
// Handle native ad impression
};
CrossMauiMTAdmob.Current.OnNativeAdClicked += (sender, args) => {
// Handle native ad clicked
};
```
--------------------------------
### Handle Rewarded Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Subscribe to various rewarded ad lifecycle events to manage ad states and user interactions. Ensure the plugin is initialized before subscribing.
```csharp
CrossMauiMTAdmob.Current.OnRewardedLoaded += (sender, args) => {
// Handle rewarded ad loaded
};
CrossMauiMTAdmob.Current.OnRewardedFailedToLoad += (sender, args) => {
// Handle rewarded ad failed to load
};
CrossMauiMTAdmob.Current.OnRewardedOpened += (sender, args) => {
// Handle rewarded ad opened
};
CrossMauiMTAdmob.Current.OnRewardedClosed += (sender, args) => {
// Handle rewarded ad closed
};
CrossMauiMTAdmob.Current.OnRewardedFailedToShow += (sender, args) => {
// Handle rewarded ad failed to show
};
CrossMauiMTAdmob.Current.OnRewardedImpression += (sender, args) => {
// Handle rewarded ad impression
};
CrossMauiMTAdmob.Current.OnRewardedClicked += (sender, args) => {
// Handle rewarded ad clicked
};
CrossMauiMTAdmob.Current.OnUserEarnedReward += (sender, args) => {
// Handle user earned reward
var reward = args.Reward;
// reward.Type and reward.Amount
};
```
--------------------------------
### Native Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for loading native ads.
```APIDOC
## Native Ads
### LoadNativeAd
Loads a single native ad.
### LoadNativeAds
Loads multiple native ads.
```
--------------------------------
### Add Xamarin.Google.iOS.UserMessagingPlatform Package
Source: https://hightouchinnovation.com/MMTAdmobGuide
If you encounter an 'Undefined symbols for architecture arm64: "OBJC_CLASS$_UMPConsentForm"...' error on iOS, add this package to your project.
```xml
```
--------------------------------
### iOS Info.plist Configuration
Source: https://hightouchinnovation.com/MMTAdmobGuide
Required keys to add to your iOS Info.plist file for AdMob integration. GADIsAdManagerApp should be set to true if this is an Ad Manager app.
```xml
GADApplicationIdentifier
YOUR APPLICATION ID
GADIsAdManagerApp
```
--------------------------------
### App Open Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for loading and managing app open ads.
```APIDOC
## App Open Ads
### LoadAd
Loads an app open ad.
```
--------------------------------
### Load Rewarded Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initiate the loading of a rewarded ad by calling the `LoadRewarded` method and providing the corresponding ad unit ID.
```csharp
void LoadRewarded(string adUnit);
```
```csharp
CrossMauiMTAdmob.Current.LoadRewarded("your-ad-unit-id");
```
--------------------------------
### Check if Rewarded Ad is Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Verify if a rewarded ad has been successfully loaded and is ready for display using the `IsRewardedLoaded` method.
```csharp
bool IsRewardedLoaded();
```
```csharp
bool isLoaded = CrossMauiMTAdmob.Current.IsRewardedLoaded();
if (isLoaded) {
// Rewarded ad is loaded
}
```
--------------------------------
### Load Native Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Loads up to 5 native ads. This method is only available on Android.
```APIDOC
## Load Native Ads
### Description
Loads up to 5 native ads. This method is only available on Android.
### Method Signature
```csharp
void LoadNativeAds(int count);
```
### Usage Example
```csharp
CrossMauiMTAdmob.Current.LoadNativeAds(5);
```
```
--------------------------------
### Load Multiple Native Ads (Android)
Source: https://hightouchinnovation.com/MMTAdmobGuide
Use this method to load up to 5 native ads. This functionality is specific to Android.
```csharp
void LoadNativeAds(int count);
```
```csharp
CrossMauiMTAdmob.Current.LoadNativeAds(5);
```
--------------------------------
### App Open Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Handles various events related to the App Open Ad lifecycle, including loading, opening, closing, and impressions.
```APIDOC
## Events
* `OnAppOpenAdLoaded`: Event raised when an app open ad is loaded.
* `OnAppOpenOpened`: Event raised when an app open ad is opened.
* `OnAppOpenClosed`: Event raised when an app open ad is closed.
* `OnAppOpenFailedToLoad`: Event raised when an app open ad fails to load.
* `OnAppOpenFailedToShow`: Event raised when an app open ad fails to show.
* `OnAppOpenImpression`: Event raised when an app open ad impression occurs.
* `OnAppOpenClicked`: Event raised when an app open ad is clicked.
```
--------------------------------
### Handle Rewarded Interstitial Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Subscribe to various events to manage the lifecycle of rewarded interstitial ads, such as loading, opening, closing, and user rewards. The OnUserEarnedReward event provides details about the reward granted to the user.
```csharp
CrossMauiMTAdmob.Current.OnRewardedInterstitialLoaded += (sender, args) => {
// Handle rewarded interstitial ad loaded
};
CrossMauiMTAdmob.Current.OnRewardedInterstitialFailedToLoad += (sender, args) => {
// Handle rewarded interstitial ad failed to load
};
CrossMauiMTAdmob.Current.OnRewardedInterstitialOpened += (sender, args) => {
// Handle rewarded interstitial ad opened
};
CrossMauiMTAdmob.Current.OnRewardedInterstitialClosed += (sender, args) => {
// Handle rewarded interstitial ad closed
};
CrossMauiMTAdmob.Current.OnRewardedInterstitialFailedToShow += (sender, args) => {
// Handle rewarded interstitial ad failed to show
};
CrossMauiMTAdmob.Current.OnRewardedInterstitialImpression += (sender, args) => {
// Handle rewarded interstitial ad impression
};
CrossMauiMTAdmob.Current.OnRewardedInterstitialClicked += (sender, args) => {
// Handle rewarded interstitial ad clicked
};
CrossMauiMTAdmob.Current.OnUserEarnedReward += (sender, args) => {
// Handle user earned reward
var reward = args.Reward;
// reward.Type and reward.Amount
};
```
--------------------------------
### Consent Management
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for initializing and managing user consent for ads.
```APIDOC
## Consent Management
### InitialiseConsent
Initializes the consent management system.
### InitialiseAndShowConsentForm
Initializes the consent system and shows the consent form.
### ShowPrivacyOptionsForm
Displays the privacy options form.
### Reset
Resets the consent state.
```
--------------------------------
### Show Rewarded Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Display the loaded rewarded ad by invoking the `ShowRewarded` method. It's recommended to check `IsRewardedLoaded` first to ensure the ad is available.
```csharp
void ShowRewarded();
```
```csharp
if (CrossMauiMTAdmob.Current.IsRewardedLoaded()) {
CrossMauiMTAdmob.Current.ShowRewarded();
}
```
--------------------------------
### Banner Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for loading and managing banner ads.
```APIDOC
## Banner Ads
### LoadAd
Loads a banner ad.
```
--------------------------------
### Banner Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Instructions on how to add banner ads to your MAUI application using XAML or code, including test IDs and collapsible banner options.
```APIDOC
## Banners
### Description
Instructions on how to add banner ads to your MAUI application using XAML or code, including test IDs and collapsible banner options.
### Adding a Banner
#### XAML
```xml
```
Remember to add this line in your XAML:
```xml
xmlns:controls="clr-namespace:Plugin.MauiMTAdmob.Controls;assembly=Plugin.MauiMTAdmob"
```
#### Code
```csharp
MTAdView ads = new MTAdView();
```
Now you can add the control to your layout.
### Test Banner IDs
To test the banner, during development, you can use the **test** Banner Id. Just remember to replace them with your IDs:
* Android: `ca-app-pub-3940256099942544/6300978111`
* iOS: `ca-app-pub-3940256099942544/2934735716`
### Collapsible Banners (Licensed version only)
To show a collapsible banner calling:
```csharp
myAds.LoadAd(CollapsibleBannerMode.Top);
```
`CollapsibleBannerMode` can have the following values: `_None_`, `_Top_`, `_Bottom_`.
### Banner Properties
For each AdView, you can set the following properties:
* `AdsId`: To add the id of your ads.
* `AdSize`: To choose the size of your banners.
* `AutoSize`: If true, the plugin will update the banner height according to the ads loaded.
### Global Properties
* `AdsId`: To add the id of your ads.
* `PersonalizedAds`: You can set it to `False` if you want to use generic ads (for GDPR...).
* `TestDevices`: You can add here the ID of your test devices.
* `UseRestrictedDataProcessing`: For compliance with the CCPA.
You can use Global Properties in this way:
```csharp
CrossMauiMTAdmob.Current.UserPersonalizedAds = true;
```
```
--------------------------------
### Resolve Duplicate androidx.lifecycle.DispatchQueue Definition
Source: https://hightouchinnovation.com/MMTAdmobGuide
To fix the 'Type androidx.lifecycle.DispatchQueue is defined multiple times' error in Android projects, import the specified Activity and Activity.Ktx packages.
```xml
"Xamarin.AndroidX.Activity" Version="1.8.2"
```
```xml
"Xamarin.AndroidX.Activity.Ktx" Version="1.8.2"
```
--------------------------------
### Handle Consent Form Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Subscribe to these events to manage the lifecycle of the consent form, including loading, opening, closing, and errors.
```csharp
CrossMauiMTAdmob.Current.OnConsentFormLoaded += (sender, args) => {
// Handle consent form loaded
};
CrossMauiMTAdmob.Current.OnConsentFormLoadFailed += (sender, args) => {
// Handle consent form load failed
};
CrossMauiMTAdmob.Current.OnConsentFormOpened += (sender, args) => {
// Handle consent form opened
};
CrossMauiMTAdmob.Current.OnConsentFormClosed += (sender, args) => {
// Handle consent form closed
};
CrossMauiMTAdmob.Current.OnConsentFormError += (sender, args) => {
// Handle consent form error
};
```
--------------------------------
### Rewarded Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for loading, showing, and managing rewarded ads.
```APIDOC
## Rewarded Ads
### LoadRewarded
Loads a rewarded ad.
### ShowRewarded
Shows a loaded rewarded ad.
### IsRewardedLoaded
Checks if a rewarded ad is currently loaded.
### GetNumberOfRewardedLoaded
Retrieves the count of loaded rewarded ads.
### EmptyRewardedAdsList
Clears the list of loaded rewarded ads.
```
--------------------------------
### Show Interstitial Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Call the `ShowInterstitial` method to display a loaded interstitial ad. Ensure `IsInterstitialLoaded` returns true before calling this method to avoid errors.
```csharp
void ShowInterstitial();
```
```csharp
if (CrossMauiMTAdmob.Current.IsInterstitialLoaded()) {
CrossMauiMTAdmob.Current.ShowInterstitial();
}
```
--------------------------------
### Load Rewarded Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initiates the loading of a rewarded ad with a specified ad unit ID.
```APIDOC
## LoadRewarded
### Description
Loads a rewarded ad.
### Method
```csharp
void LoadRewarded(string adUnit);
```
### Parameters
#### Path Parameters
- **adUnit** (string) - Required - The ad unit ID for the rewarded ad.
```
--------------------------------
### Check if Rewarded Interstitial Ad is Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Determine if a rewarded interstitial ad is ready to be displayed. This check should be performed before attempting to show the ad.
```csharp
bool isLoaded = CrossMauiMTAdmob.Current.IsRewardedInterstitialLoaded();
if (isLoaded) {
// Rewarded interstitial ad is loaded
}
```
--------------------------------
### Request User Consent
Source: https://hightouchinnovation.com/MMTAdmobGuide
Requests user consent using the consent form. This is typically called automatically on initialization, but can be shown manually.
```APIDOC
## Requesting User Consent
### Description
Requests user consent using the consent form. This is typically called automatically on initialization, but can be shown manually if configured to do so.
### Method Signature
```csharp
void InitialiseAndShowConsentForm();
```
### Usage Example
```csharp
CrossMauiMTAdmob.Current.InitialiseAndShowConsentForm();
```
```
--------------------------------
### Native Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Handles various events related to the native ad lifecycle.
```APIDOC
## Handling Native Ad Events
### Description
The plugin provides several events to handle native ad lifecycle events.
### Events
- `OnNativeAdLoaded`: Raised when a native ad is loaded.
- `OnNativeAdOpened`: Raised when a native ad is opened.
- `OnNativeAdClosed`: Raised when a native ad is closed.
- `OnNativeAdFailedToLoad`: Raised when a native ad fails to load.
- `OnNativeAdFailedToShow`: Raised when a native ad fails to show.
- `OnNativeAdImpression`: Raised when a native ad impression occurs.
- `OnNativeAdClicked`: Raised when a native ad is clicked.
### Usage Example
```csharp
CrossMauiMTAdmob.Current.OnNativeAdLoaded += (sender, args) => {
// Handle native ad loaded
};
CrossMauiMTAdmob.Current.OnNativeAdOpened += (sender, args) => {
// Handle native ad opened
};
CrossMauiMTAdmob.Current.OnNativeAdClosed += (sender, args) => {
// Handle native ad closed
};
CrossMauiMTAdmob.Current.OnNativeAdFailedToLoad += (sender, args) => {
// Handle native ad failed to load
};
CrossMauiMTAdmob.Current.OnNativeAdFailedToShow += (sender, args) => {
// Handle native ad failed to show
};
CrossMauiMTAdmob.Current.OnNativeAdImpression += (sender, args) => {
// Handle native ad impression
};
CrossMauiMTAdmob.Current.OnNativeAdClicked += (sender, args) => {
// Handle native ad clicked
};
```
```
--------------------------------
### Handle Interstitial Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Subscribe to various events to manage the lifecycle of interstitial ads, including loading, failure, opening, closing, and impressions. The `MTEventArgs` may contain additional failure information.
```csharp
CrossMauiMTAdmob.Current.OnInterstitialLoaded += (sender, args) => {
// Handle interstitial ad loaded
};
CrossMauiMTAdmob.Current.OnInterstitialFailedToLoad += (sender, args) => {
// Handle interstitial ad failed to load
};
CrossMauiMTAdmob.Current.OnInterstitialOpened += (sender, args) => {
// Handle interstitial ad opened
};
CrossMauiMTAdmob.Current.OnInterstitialClosed += (sender, args) => {
// Handle interstitial ad closed
};
CrossMauiMTAdmob.Current.OnInterstitialFailedToShow += (sender, args) => {
// Handle interstitial ad failed to show
};
CrossMauiMTAdmob.Current.OnInterstitialImpression += (sender, args) => {
// Handle interstitial ad impression
};
CrossMauiMTAdmob.Current.OnInterstitialClicked += (sender, args) => {
// Handle interstitial ad clicked
};
```
--------------------------------
### Show Rewarded Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Displays the loaded rewarded ad to the user.
```APIDOC
## ShowRewarded
### Description
Shows the loaded rewarded ad.
### Method
```csharp
void ShowRewarded();
```
### Example
```csharp
if (CrossMauiMTAdmob.Current.IsRewardedLoaded()) {
CrossMauiMTAdmob.Current.ShowRewarded();
}
```
```
--------------------------------
### Check if Interstitial Ad is Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Use the `IsInterstitialLoaded` method to determine if an interstitial ad is ready to be shown. This is a prerequisite for calling `ShowInterstitial`.
```csharp
bool IsInterstitialLoaded();
```
```csharp
bool isLoaded = CrossMauiMTAdmob.Current.IsInterstitialLoaded();
if (isLoaded) {
// Interstitial ad is loaded
}
```
--------------------------------
### Load Rewarded Interstitial Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Initiate the loading of a rewarded interstitial ad by providing its unique ad unit ID.
```csharp
CrossMauiMTAdmob.Current.LoadRewardedInterstitial("your-ad-unit-id");
```
--------------------------------
### Show Rewarded Interstitial Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Display the loaded rewarded interstitial ad to the user. Ensure the ad is loaded before calling this method.
```csharp
if (CrossMauiMTAdmob.Current.IsRewardedInterstitialLoaded()) {
CrossMauiMTAdmob.Current.ShowRewardedInterstitial();
}
```
--------------------------------
### Rewarded Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Subscribe to various events to handle the lifecycle of rewarded ads, such as loading, failure, opening, closing, impression, clicks, and user rewards.
```APIDOC
## Handling Rewarded Ad Events
The plugin provides several events to handle rewarded ad lifecycle events:
* `event EventHandler OnRewardedLoaded`: Raised when a rewarded ad is loaded.
* `event EventHandler OnRewardedFailedToLoad`: Raised when a rewarded ad fails to load.
* `event EventHandler OnRewardedOpened`: Raised when a rewarded ad is opened.
* `event EventHandler OnRewardedClosed`: Raised when a rewarded ad is closed.
* `event EventHandler OnRewardedFailedToShow`: Raised when a rewarded ad fails to show.
* `event EventHandler OnRewardedImpression`: Raised when a rewarded ad impression occurs.
* `event EventHandler OnRewardedClicked`: Raised when a rewarded ad is clicked.
* `event EventHandler OnUserEarnedReward`: Raised when the user earns a reward.
### Example
```csharp
CrossMauiMTAdmob.Current.OnRewardedLoaded += (sender, args) => {
// Handle rewarded ad loaded
};
CrossMauiMTAdmob.Current.OnRewardedFailedToLoad += (sender, args) => {
// Handle rewarded ad failed to load
};
CrossMauiMTAdmob.Current.OnRewardedOpened += (sender, args) => {
// Handle rewarded ad opened
};
CrossMauiMTAdmob.Current.OnRewardedClosed += (sender, args) => {
// Handle rewarded ad closed
};
CrossMauiMTAdmob.Current.OnRewardedFailedToShow += (sender, args) => {
// Handle rewarded ad failed to show
};
CrossMauiMTAdmob.Current.OnRewardedImpression += (sender, args) => {
// Handle rewarded ad impression
};
CrossMauiMTAdmob.Current.OnRewardedClicked += (sender, args) => {
// Handle rewarded ad clicked
};
CrossMauiMTAdmob.Current.OnUserEarnedReward += (sender, args) => {
// Handle user earned reward
var reward = args.Reward;
// reward.Type and reward.Amount
};
```
```
--------------------------------
### Check Rewarded Ad Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Determines if a rewarded ad is currently loaded and ready for display.
```APIDOC
## IsRewardedLoaded
### Description
Checks if a rewarded ad is loaded.
### Method
```csharp
bool IsRewardedLoaded();
```
### Example
```csharp
bool isLoaded = CrossMauiMTAdmob.Current.IsRewardedLoaded();
if (isLoaded) {
// Rewarded ad is loaded
}
```
```
--------------------------------
### IsRewardedInterstitialLoaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Checks if a rewarded interstitial ad has been successfully loaded and is ready to be shown.
```APIDOC
## Checking if a Rewarded Interstitial Ad is Loaded
To check if a rewarded interstitial ad is loaded, use the `IsRewardedInterstitialLoaded` method:
```csharp
bool IsRewardedInterstitialLoaded();
```
### Example
```csharp
bool isLoaded = CrossMauiMTAdmob.Current.IsRewardedInterstitialLoaded();
if (isLoaded) {
// Rewarded interstitial ad is loaded
}
```
```
--------------------------------
### Load Interstitial Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Method to load an interstitial ad. Requires the ad unit ID as a string parameter.
```csharp
CrossMauiMTAdmob.Current.LoadInterstitial("your-ad-unit-id");
```
--------------------------------
### LoadRewardedInterstitial
Source: https://hightouchinnovation.com/MMTAdmobGuide
Loads a rewarded interstitial ad using the provided ad unit ID. This prepares the ad to be shown later.
```APIDOC
## Loading a Rewarded Interstitial Ad
To load a rewarded interstitial ad, use the `LoadRewardedInterstitial` method with the specified ad unit:
```csharp
void LoadRewardedInterstitial(string adUnit);
```
### Example
```csharp
CrossMauiMTAdmob.Current.LoadRewardedInterstitial("your-ad-unit-id");
```
```
--------------------------------
### Check User Consent Status
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieves the current consent status of the user. Use this to determine if consent has been obtained before serving personalized ads.
```csharp
ConsentStatus GetConsentStatus();
```
```csharp
ConsentStatus status = CrossMauiMTAdmob.Current.GetConsentStatus();
if (status == ConsentStatus.Obtained) {
// User has granted consent
} else {
// User has not granted consent
}
```
--------------------------------
### Interstitial Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for loading, showing, and managing interstitial ads.
```APIDOC
## Interstitial Ads
### LoadInterstitial
Loads an interstitial ad.
### ShowInterstitial
Shows a loaded interstitial ad.
### IsInterstitialLoaded
Checks if an interstitial ad is currently loaded.
### GetNumberOfInterstitialsLoaded
Retrieves the count of loaded interstitial ads.
### EmptyInterstitialAdsList
Clears the list of loaded interstitial ads.
```
--------------------------------
### Rewarded Interstitial Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Handles the lifecycle events for rewarded interstitial ads, such as loading, opening, closing, and user rewards.
```APIDOC
## Handling Rewarded Interstitial Ad Events
The plugin provides several events to handle rewarded interstitial ad lifecycle events:
* `event EventHandler OnRewardedInterstitialLoaded`: Raised when a rewarded interstitial ad is loaded.
* `event EventHandler OnRewardedInterstitialFailedToLoad`: Raised when a rewarded interstitial ad fails to load.
* `event EventHandler OnRewardedInterstitialOpened`: Raised when a rewarded interstitial ad is opened.
* `event EventHandler OnRewardedInterstitialClosed`: Raised when a rewarded interstitial ad is closed.
* `event EventHandler OnRewardedInterstitialFailedToShow`: Raised when a rewarded interstitial ad fails to show.
* `event EventHandler OnRewardedInterstitialImpression`: Raised when a rewarded interstitial ad impression occurs.
* `event EventHandler OnRewardedInterstitialClicked`: Raised when a rewarded interstitial ad is clicked.
* `event EventHandler OnUserEarnedReward`: Raised when the user earns a reward.
```
--------------------------------
### Check User Consent Status
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieves the current user consent status.
```APIDOC
## Checking User Consent Status
### Description
Retrieves the current user consent status.
### Method Signature
```csharp
ConsentStatus GetConsentStatus();
```
### Return Value
- `ConsentStatus`: An enum representing the user's consent status (e.g., `Obtained`, `Required`, `NotRequired`).
### Usage Example
```csharp
ConsentStatus status = CrossMauiMTAdmob.Current.GetConsentStatus();
if (status == ConsentStatus.Obtained) {
// User has granted consent
} else {
// User has not granted consent
}
```
```
--------------------------------
### Load Collapsible Banner
Source: https://hightouchinnovation.com/MMTAdmobGuide
Method to load a collapsible banner ad. Specify the banner's position using CollapsibleBannerMode.
```csharp
myAds.LoadAd(CollapsibleBannerMode.Top);
```
--------------------------------
### Android Manifest Meta-Data
Source: https://hightouchinnovation.com/MMTAdmobGuide
Configuration for AdMob application ID in Android's AppManifest. Replace 'YOUR APPLICATION ID' with your actual AdMob App ID.
```xml
```
--------------------------------
### Consent Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Handles various events related to the user consent form lifecycle.
```APIDOC
## Handling Consent Events
### Description
The plugin provides several events to handle user consent lifecycle events.
### Events
- `OnConsentFormLoaded`: Raised when the consent form is loaded.
- `OnConsentFormLoadFailed`: Raised when the consent form fails to load.
- `OnConsentFormOpened`: Raised when the consent form is opened.
- `OnConsentFormClosed`: Raised when the consent form is closed.
- `OnConsentFormError`: Raised when there is an error with the consent form.
### Usage Example
```csharp
CrossMauiMTAdmob.Current.OnConsentFormLoaded += (sender, args) => {
// Handle consent form loaded
};
CrossMauiMTAdmob.Current.OnConsentFormLoadFailed += (sender, args) => {
// Handle consent form load failed
};
CrossMauiMTAdmob.Current.OnConsentFormOpened += (sender, args) => {
// Handle consent form opened
};
CrossMauiMTAdmob.Current.OnConsentFormClosed += (sender, args) => {
// Handle consent form closed
};
CrossMauiMTAdmob.Current.OnConsentFormError += (sender, args) => {
// Handle consent form error
};
```
```
--------------------------------
### MAUI MTAdmob Namespace
Source: https://hightouchinnovation.com/MMTAdmobGuide
The namespace declaration required in XAML to use the MTAdView control.
```xml
xmlns:controls="clr-namespace:Plugin.MauiMTAdmob.Controls;assembly=Plugin.MauiMTAdmob"
```
--------------------------------
### Show Interstitial Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Displays the loaded interstitial ad to the user.
```APIDOC
## ShowInterstitial
### Description
Shows the loaded interstitial ad.
### Method
```csharp
void ShowInterstitial();
```
### Example
```csharp
if (CrossMauiMTAdmob.Current.IsInterstitialLoaded()) {
CrossMauiMTAdmob.Current.ShowInterstitial();
}
```
```
--------------------------------
### ShowRewardedInterstitial
Source: https://hightouchinnovation.com/MMTAdmobGuide
Displays the loaded rewarded interstitial ad to the user. This should only be called if `IsRewardedInterstitialLoaded` returns true.
```APIDOC
## Showing a Rewarded Interstitial Ad
To show the loaded rewarded interstitial ad, use the `ShowRewardedInterstitial` method:
```csharp
void ShowRewardedInterstitial();
```
### Example
```csharp
if (CrossMauiMTAdmob.Current.IsRewardedInterstitialLoaded()) {
CrossMauiMTAdmob.Current.ShowRewardedInterstitial();
}
```
```
--------------------------------
### Interstitial Ad Events
Source: https://hightouchinnovation.com/MMTAdmobGuide
Handles various lifecycle events for interstitial ads.
```APIDOC
## Interstitial Ad Events
### Description
Handles interstitial ad lifecycle events.
### Events
- `OnInterstitialLoaded`: Raised when an interstitial ad is loaded.
- `OnInterstitialFailedToLoad`: Raised when an interstitial ad fails to load.
- `OnInterstitialOpened`: Raised when an interstitial ad is opened.
- `OnInterstitialClosed`: Raised when an interstitial ad is closed.
- `OnInterstitialFailedToShow`: Raised when an interstitial ad fails to show.
- `OnInterstitialImpression`: Raised when an interstitial ad impression occurs.
- `OnInterstitialClicked`: Raised when an interstitial ad is clicked.
### Example
```csharp
CrossMauiMTAdmob.Current.OnInterstitialLoaded += (sender, args) => {
// Handle interstitial ad loaded
};
CrossMauiMTAdmob.Current.OnInterstitialFailedToLoad += (sender, args) => {
// Handle interstitial ad failed to load
};
CrossMauiMTAdmob.Current.OnInterstitialOpened += (sender, args) => {
// Handle interstitial ad opened
};
CrossMauiMTAdmob.Current.OnInterstitialClosed += (sender, args) => {
// Handle interstitial ad closed
};
CrossMauiMTAdmob.Current.OnInterstitialFailedToShow += (sender, args) => {
// Handle interstitial ad failed to show
};
CrossMauiMTAdmob.Current.OnInterstitialImpression += (sender, args) => {
// Handle interstitial ad impression
};
CrossMauiMTAdmob.Current.OnInterstitialClicked += (sender, args) => {
// Handle interstitial ad clicked
};
```
```
--------------------------------
### Rewarded Interstitial Ads
Source: https://hightouchinnovation.com/MMTAdmobGuide
Methods for loading, showing, and managing rewarded interstitial ads.
```APIDOC
## Rewarded Interstitial Ads
### LoadRewardedInterstitial
Loads a rewarded interstitial ad.
### ShowRewardedInterstitial
Shows a loaded rewarded interstitial ad.
### IsRewardedInterstitialLoaded
Checks if a rewarded interstitial ad is currently loaded.
### GetNumberOfRewardedInterstitialsLoaded
Retrieves the count of loaded rewarded interstitial ads.
### EmptyRewardedInterstitialsAdsList
Clears the list of loaded rewarded interstitial ads.
```
--------------------------------
### Empty Rewarded Ads List
Source: https://hightouchinnovation.com/MMTAdmobGuide
Clear the list of loaded rewarded ads. The library typically manages this automatically by removing ads older than one hour.
```csharp
CrossMauiMTAdmob.Current.EmptyRewardedAdsList();
```
--------------------------------
### MAUI MT AdView XAML
Source: https://hightouchinnovation.com/MMTAdmobGuide
Declaration of an MTAdView control in XAML for displaying banners. Ensure the correct namespace is included.
```xml
```
--------------------------------
### Check Interstitial Ad Loaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Checks if an interstitial ad is currently loaded and ready to be displayed.
```APIDOC
## IsInterstitialLoaded
### Description
Checks if an interstitial ad is loaded.
### Method
```csharp
bool IsInterstitialLoaded();
```
### Example
```csharp
bool isLoaded = CrossMauiMTAdmob.Current.IsInterstitialLoaded();
if (isLoaded) {
// Interstitial ad is loaded
}
```
```
--------------------------------
### Load Interstitial Ad
Source: https://hightouchinnovation.com/MMTAdmobGuide
Loads an interstitial ad using the provided ad unit ID. This is part of the IMTAdmob Interstitials Documentation.
```APIDOC
## Loading an Interstitial Ad
### Description
Loads an interstitial ad using the provided ad unit ID. This is part of the IMTAdmob Interstitials Documentation.
### Method Signature
```csharp
void LoadInterstitial(string adUnit);
```
### Example
```csharp
CrossMauiMTAdmob.Current.LoadInterstitial("your-ad-unit-id");
```
```
--------------------------------
### Empty Interstitial Ads List
Source: https://hightouchinnovation.com/MMTAdmobGuide
Use `EmptyInterstitialAdsList` to clear the list of loaded interstitial ads. The library typically manages this automatically by removing old ads.
```csharp
void EmptyInterstitialAdsList();
```
```csharp
CrossMauiMTAdmob.Current.EmptyInterstitialAdsList();
```
--------------------------------
### Empty Interstitial Ads List
Source: https://hightouchinnovation.com/MMTAdmobGuide
Clears the list of all loaded interstitial ads.
```APIDOC
## EmptyInterstitialAdsList
### Description
Empties the interstitial ads list.
### Method
```csharp
void EmptyInterstitialAdsList();
```
### Example
```csharp
CrossMauiMTAdmob.Current.EmptyInterstitialAdsList();
```
### Note
This method clears the list of loaded interstitial ads. The library automatically removes old ads, so this is typically not needed.
```
--------------------------------
### EmptyRewardedAdsList
Source: https://hightouchinnovation.com/MMTAdmobGuide
Clears the list of loaded rewarded ads. This method is typically not needed as the library automatically manages old ads, but can be used for manual cleanup.
```APIDOC
## Emptying the Rewarded Ads List
To empty the rewarded ads list, use the `EmptyRewardedAdsList` method:
```csharp
void EmptyRewardedAdsList();
```
### Example
```csharp
CrossMauiMTAdmob.Current.EmptyRewardedAdsList();
```
Use this method to clear the list of loaded rewarded ads. Normally you don't need to use it as the library automatically removes loaded ads that are too old (1 hour) as they might be not valid anymore.
```
--------------------------------
### Empty Rewarded Interstitial Ads List
Source: https://hightouchinnovation.com/MMTAdmobGuide
Clear the list of all loaded rewarded interstitial ads. This is typically handled automatically by the library, which removes ads older than one hour.
```csharp
CrossMauiMTAdmob.Current.EmptyRewardedInterstitialAdsList();
```
--------------------------------
### Empty Rewarded Interstitial Ads List
Source: https://hightouchinnovation.com/MMTAdmobGuide
Clears the list of loaded rewarded interstitial ads. This is typically handled automatically by the library.
```APIDOC
## Emptying the Rewarded Interstitial Ads List
To empty the rewarded interstitial ads list, use the `EmptyRewardedInterstitialAdsList` method:
```
void EmptyRewardedInterstitialAdsList();
```
```
--------------------------------
### GetNumberOfRewardedLoaded
Source: https://hightouchinnovation.com/MMTAdmobGuide
Retrieves the number of rewarded ads currently loaded. This is useful for managing ad inventory, especially when the licensed version allows multiple ads.
```APIDOC
## Getting the Number of Rewarded Ads Loaded
To get the number of rewarded ads loaded, use the `GetNumberOfRewardedLoaded` method:
```csharp
int GetNumberOfRewardedLoaded();
```
### Example
```csharp
int numberOfRewarded = CrossMauiMTAdmob.Current.GetNumberOfRewardedLoaded();
```
Only the licensed version allows to load multiple rewarded ads and show them when needed.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.