BlueStack.SDK.Maui
1.0.0-alpha1
See the version list below for details.
dotnet add package BlueStack.SDK.Maui --version 1.0.0-alpha1
NuGet\Install-Package BlueStack.SDK.Maui -Version 1.0.0-alpha1
<PackageReference Include="BlueStack.SDK.Maui" Version="1.0.0-alpha1" />
paket add BlueStack.SDK.Maui --version 1.0.0-alpha1
#r "nuget: BlueStack.SDK.Maui, 1.0.0-alpha1"
// Install BlueStack.SDK.Maui as a Cake Addin #addin nuget:?package=BlueStack.SDK.Maui&version=1.0.0-alpha1&prerelease // Install BlueStack.SDK.Maui as a Cake Tool #tool nuget:?package=BlueStack.SDK.Maui&version=1.0.0-alpha1&prerelease
BlueStack-SDK MAUI
Getting started
BlueStack-SDK MAUI library provides functionality to integrate native(Android and iOS) BlueStack SDK into MAUI project. Using this library developer can display ads on their application from Madvertise and other third-party ad networks.
Prerequisites
.NET:
- .NET 7.0
iOS:
- Xcode 14.3 or later
- Minimum iOS version 13.0
Android:
- Android 5.0 (API 21) or higher
Using BlueStackSDK MAUI library
Initialization
Initialize BlueStack sdk with appId, settings and a completion block.
public partial class MainPage : ContentPage
{
private BannerAd _bannerAd;
public MainPage() {
Settings settings = new Settings(true);
BlueStackAds.Initialize("YOUR_APP_ID_HERE", settings, OnAdSDKInitialized);
}
private void OnAdSDKInitialized(InitializationStatus initializationStatus)
{
Debug.Print("BlueStack SDK has been initialized");
}
}
Showing Banner Ad
Step 1. Instantiate Banner Ad
You can instanstiate a Banner ad right after SDK finishes it's initialization. You have to pass the platform specific banner placement id and banner AdPosition
in BannerAd
constructor.
_bannerAd = new BannerAd(adUnitId, AdPosition.Top);
Banner ad supports ad positions of following types:
Position | value | Definition |
---|---|---|
Top | 0 | Show banner at the top of the screen |
Bottom | 1 | Show banner at the bottom of the screen |
Step 2. Register event listeners
BannerAd exposes the following events through it's lifecycle.
Methods | Definition |
---|---|
OnBannerDidLoad | Ad is successfully loaded and SDK is ready to display the ad. |
OnBannerDidFailed | The ad failed to load or display. An additional error parameter of type BlueStackError contains the reason of the failure. |
OnAdClicked | User has clicked the ad. Ad may open a link in browser. |
OnBannerDisplay | The banner ad has been displayed on the screen. |
OnBannerHide | The banner ad has been hidden. |
OnBannerDidRefresh | The banner ad has been refreshed |
OnBannerDidFailToRefresh | The banner ad has been failed to refresh |
To register for banner ad events, add the following code after instantiating BannerAd.
_bannerAd.OnBannerDidLoad += (sender, args) =>
{
Debug.Log("OnBannerDidLoad");
};
_bannerAd.OnBannerDidFailed += (sender, args) =>
{
Debug.LogError("OnBannerDidFailed: " + args.Message);
};
_bannerAd.OnBannerDisplay += (sender, args) =>
{
Debug.Log("OnBannerDisplay");
};
_bannerAd.OnBannerHide += (sender, args) =>
{
Debug.Log("OnBannerHide");
};
_bannerAd.OnAdClicked += (sender, args) =>
{
Debug.Log("OnAdClicked");
};
_bannerAd.OnBannerDidRefresh += (sender, args) =>
{
Debug.Log("OnBannerDidRefresh");
};
_bannerAd.OnBannerDidFailToRefresh += (sender, args) =>
{
Debug.LogError("OnBannerDidFailToRefresh: " + args.Message);
};
:::caution Make sure you only register event listener once. :::
Step 3. Load Banner ad
BannerAd takes AdSize
to load banner. It also have another Load
method that takes Preference
instance along with AdSize
. Banner Ad supports following ad sizes:
Ad Size | Definition |
---|---|
Banner | 320x50 |
DynamicBanner | 0x50 |
LargeBanner | 320x100 |
FullBanner | 468x60 |
Leaderboard | 728x90 |
DynamicLeaderboard | 0x90 |
MediumRectangle | 300x250 |
- Without Preference
_bannerAd.Load(AdSize.Banner);
- With Preference
private LoadBannerAdWithPreference() {
Preference _preference = new Preference();
Location myLocation = new Location(Location.NONE_PROVIDER)
{
Latitude = 35.757866,
Longitude = 10.810547
};
_preference.SetAge(25);
_preference.SetLanguage("en");
_preference.SetGender(Gender.Male);
_preference.SetKeyword("brand=myBrand;category=sport");
_preference.SetLocation(myLocation, 1);
_preference.SetContentUrl("https://madvertise.com/en/");
_bannerAd.Load(AdSize.Banner, _preference);
}
**Note 😗*
The setLocation method takes the following parameters:
- the Location instance.
- the CONSENT_FLAG value (corresponds to a int : 0,1,2 or 3).
- 0 = Not allow to send location.
- 1 = When you managed location according to consent value.
- 2 and 3 = Allow the SDK to managed location directly in accordance with the consent value use TCF v1 or TCF v2, see with the madvertise team it depends on your implementation.
Step 4. Show Banner ad
After loading the banner ad you can request it to be displayed.
_bannerAd.Show();
Hide Banner ad
Banner Ad can be set to be hidden also.
_bannerAd.Hide();
Change banner ad position
You can set banner ad position runtime.
_bannerAd.SetPosition(adPosition);
Destroy banner ad
Destroy banner ad if you want to create a new one.
_bannerAd.Destroy();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-android33.0 is compatible. net7.0-ios was computed. net7.0-ios16.1 is compatible. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
-
net7.0-android33.0
- No dependencies.
-
net7.0-ios16.1
- BlueStack.SDK.Core.iOS.Binding (>= 1.0.0-preview.1)
- Xamarin.Google.iOS.MobileAds (>= 8.13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.