Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS iOS Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /iOS/GoogleAds/AdMob Test
This example is the version from Sun, 5th Nov 2022.
Project "AdMob Test.xojo_binary_project"
Class App Inherits MobileApplication
EventHandler Function UnhandledException(exc As RuntimeException) As Boolean
Break
End EventHandler
End Class
Class MainScreen Inherits MobileScreen
Control StartButton Inherits MobileButton
ControlInstance StartButton Inherits MobileButton
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
EventHandler Sub Pressed()
me.Enabled = false
System.DebugLog CurrentMethodName
sharedInstance = new GADMobileAds
sharedInstance.Parent = self
VersionLabel.Text = sharedInstance.sdkVersion
dim RequestConfiguration as GADRequestConfigurationMBS = sharedInstance.requestConfiguration
dim TestDeviceIdentifiers() as string
TestDeviceIdentifiers.append RequestConfiguration.GADSimulatorID
'add more test devices
'RequestConfiguration.setTestDeviceIdentifiers TestDeviceIdentifiers
// starts and calls event later
sharedInstance.start
TrackingButton.Enabled = true
End EventHandler
End Control
Control ShowAdButton Inherits MobileButton
ControlInstance ShowAdButton Inherits MobileButton
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
EventHandler Sub Pressed()
const adid = "ca-app-pub-3940256099942544/4411468910" // this is a special test ID. Replace with your's for shipping!
// test ids from google website
// https://developers.google.com/admob/ios/test-ads
me.Enabled = false
// let's load and add and show it when ready
dim request as GADRequestMBS = GADRequestMBS.request
fullscreenAd = new GADInterstitialAd
fullscreenAd.loadWithAdUnitID adid, request
End EventHandler
End Control
Control VersionLabel Inherits MobileLabel
ControlInstance VersionLabel Inherits MobileLabel
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
End Control
Control TrackingButton Inherits MobileButton
ControlInstance TrackingButton Inherits MobileButton
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
EventHandler Sub Pressed()
me.Enabled = false
sharedInstance.requestTrackingAuthorization
End EventHandler
End Control
Control TrackingLabel Inherits MobileLabel
ControlInstance TrackingLabel Inherits MobileLabel
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
End Control
Control ShowBannerButton Inherits MobileButton
ControlInstance ShowBannerButton Inherits MobileButton
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
EventHandler Sub Pressed()
const adid = "ca-app-pub-3940256099942544/2934735716" // this is a special test ID. Replace with your's for shipping!
me.Enabled = false
// let's load and add and show it when ready
dim request as GADRequestMBS = GADRequestMBS.request
BannerView = new GADBannerView( GADAdSizeMBS.Banner)
BannerView.parent = self
BannerView.adUnitID = adid
BannerView.loadRequest request
BannerView.AddToControl self.Canvas1
End EventHandler
End Control
Control Canvas1 Inherits MobileCanvas
ControlInstance Canvas1 Inherits MobileCanvas
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
End Control
Control ShowOpenButton Inherits MobileButton
ControlInstance ShowOpenButton Inherits MobileButton
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
EventHandler Sub Pressed()
const adid = "ca-app-pub-3940256099942544/5662855259" // this is a special test ID. Replace with your's for shipping!
me.Enabled = false
// let's load and add and show it when ready
dim request as GADRequestMBS = GADRequestMBS.request
dim orientation as integer
orientation = GADAppOpenAdMBS.DeviceOrientationPortrait
OpenAd = new GADAppOpenAd
OpenAd.loadWithAdUnitID adid, orientation, request
End EventHandler
End Control
EventHandler Sub Opening()
System.DebugLog CurrentMethodName
CheckTrackingStatus
End EventHandler
Sub CheckTrackingStatus()
dim trackingStatus as integer = GADMobileAdsMBS.trackingAuthorizationStatus
Select case trackingStatus
case GADMobileAdsMBS.TrackingManagerAuthorizationStatusAuthorized
TrackingLabel.Text = "Status Authorized"
case GADMobileAdsMBS.TrackingManagerAuthorizationStatusDenied
TrackingLabel.Text = "Status Denied"
case GADMobileAdsMBS.TrackingManagerAuthorizationStatusNotDetermined
TrackingLabel.Text = "Status Not Determined"
case GADMobileAdsMBS.TrackingManagerAuthorizationStatusRestricted
TrackingLabel.Text = "Status Restricted"
end Select
End Sub
Sub Started()
ShowAdButton.Enabled = true
ShowBannerButton.Enabled = true
ShowOpenButton.Enabled = true
End Sub
Property BannerView As GADBannerView
Property Private OpenAd As GADAppOpenAd
Property fullscreenAd As GADInterstitialAd
Property sharedInstance As GADMobileAds
End Class
Class LaunchScreen Inherits iosView
End Class
ExternalFile Info
End ExternalFile
Class GADMobileAds Inherits GADMobileAdsMBS
ComputedProperty Parent As MainScreen
Sub Set()
if value = nil then
mParent = nil
else
mParent = new WeakRef(value)
end if
End Set
Sub Get()
if mParent <> nil then
dim v as Variant = mParent.Value
return v
end if
End Get
End ComputedProperty
EventHandler Sub requestTrackingAuthorizationCompleted(status as integer)
parent.CheckTrackingStatus
End EventHandler
EventHandler Sub startCompleted()
System.DebugLog CurrentMethodName
'MessageBox "Started"
parent.Started
End EventHandler
Property Private mParent As WeakRef
End Class
Class GADInterstitialAd Inherits GADInterstitialAdMBS
EventHandler Sub DidDismissFullScreenContent()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidFailToPresentFullScreenContentWithError(error as NSErrorMBS)
System.DebugLog CurrentMethodName
if error <> nil then
System.DebugLog error.LocalizedDescription
end if
End EventHandler
EventHandler Sub DidRecordClick()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidRecordImpression()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub WillDismissFullScreenContent()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub WillPresentFullScreenContent()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub loadCompleted(error as NSErrorMBS)
System.DebugLog CurrentMethodName
if error <> nil then
MessageBox error.LocalizedDescription
return
end if
// show ad
me.Present
End EventHandler
End Class
Class GADBannerView Inherits GADBannerViewMBS
ComputedProperty Parent As MainScreen
Sub Set()
if value = nil then
mParent = nil
else
mParent = new WeakRef(value)
end if
End Set
Sub Get()
if mParent <> nil then
dim v as Variant = mParent.Value
return v
end if
End Get
End ComputedProperty
EventHandler Sub DidDismissScreen()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidFailToReceiveAdWithError(error as NSErrorMBS)
System.DebugLog CurrentMethodName
if error <> nil then
System.DebugLog error.LocalizedDescription
end if
End EventHandler
EventHandler Sub DidReceiveAd()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidRecordClick()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidRecordImpression()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub WillDismissScreen()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub WillPresentScreen()
System.DebugLog CurrentMethodName
End EventHandler
Property Private mParent As WeakRef
End Class
Class GADAppOpenAd Inherits GADAppOpenAdMBS
EventHandler Sub DidDismissFullScreenContent()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidFailToPresentFullScreenContentWithError(error as NSErrorMBS)
System.DebugLog CurrentMethodName
if error <> nil then
System.DebugLog error.LocalizedDescription
end if
End EventHandler
EventHandler Sub DidRecordClick()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub DidRecordImpression()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub WillDismissFullScreenContent()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub WillPresentFullScreenContent()
System.DebugLog CurrentMethodName
End EventHandler
EventHandler Sub loadCompleted(error as NSErrorMBS)
System.DebugLog CurrentMethodName
if error <> nil then
MessageBox error.LocalizedDescription
return
end if
// show ad
me.Present
End EventHandler
End Class
End Project
The items on this page are in the following plugins: MBS iOS Plugin.