iOS Question Size of iAd Banner adds

Andrew Lindsay

Member
Licensed User
Longtime User
I’m not sure, I was thinking of just a small banner ad, either at the top or bottom of the form.

I thought that there may be a control to add via the visual designer, but when I add the iAdMob library to the project, I don't see anything in the list of controls as a native control or in the custom views.

Is there a specific iOS tutorial that shows the steps necessary to add a banner ad to an iOS form?

Best regards

Andrew
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is very similar to B4A AdMob. You can see the standard sizes here: https://www.b4x.com/b4i/help/iadmob.html#adview_size_banner
Smart banner sizes: https://developers.google.com/admob/android/banner#smart_banners

You cannot add it with the designer as it is not implemented as a custom view.
You need to add it in your code:
B4X:
ad.Initialize("ad", "ca-app-pub-126751111111/111111", Page1, ad.SIZE_BANNER)
Page1.RootPanel.AddView(ad, 0, 0, Page1.RootPanel.Width, 60) 'add an ad at the top of the screen

To add it to the bottom of the screen you need to handle the Page_Resize event and set the ad position there.
 
Upvote 0

Andrew Lindsay

Member
Licensed User
Longtime User
OK, so I've added the code, and looked at the Android tutorial, but still I'm having troubles.

My code looks like the following.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
  
    Private AdView1 As AdView

    Private Button1 As Button
    Private TextField1 As TextField
    Private TextView1 As TextView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Prog2")
    Page1.Title = "Factor Tree Creator - Free"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
  
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    TextView1.Height= Height - TextView1.top - 10dip
    AdView1.Initialize("Ad", "ca-app-pub-6456812152893790/3462421222", Page1, AdView1.SIZE_BANNER)
    Page1.RootPanel.AddView(AdView1, 0, 0, Page1.RootPanel.Width, 50)
    AdView1.LoadAd
End Sub

And the log show the following.
B4X:
Application_Start
Application_Active
<Google> Advertising tracking may be disabled. To get test ads on this device, enable advertising tracking.
<Google:HTML> You are currently using version 7.14.0 of the SDK. Please consider updating your SDK to the most recent SDK version to get the latest features and bug fixes. The latest SDK can be downloaded from https://goo.gl/UoiJ8F. A full list of release notes is available at https://developers.google.com/admob/ios/rel-notes.
Failed: Error Domain=com.google.ads Code=1 "Request Error: No ad to show." UserInfo={NSLocalizedDescription=Request Error: No ad to show., NSLocalizedFailureReason=Request Error: No ad to show.}
Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 4072550144015629828_PortraitChoco_iPhone-Simple-Pad_Default
Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 4072550144015629828_PortraitChoco_iPhone-Simple-Pad_Default
<B4IList: (
    2,
    2,
    2,
    3,
    11,
    47189
)>
Failed: Error Domain=com.google.ads Code=1 "Request Error: No ad to show." UserInfo={NSLocalizedDescription=Request Error: No ad to show., NSLocalizedFailureReason=Request Error: No ad to show.}
Application_Inactive
Application_Background

Can anyone suggest what I am missing/doing incorrectly?

Regards

Andrew
 
Upvote 0

MikeH

Well-Known Member
Licensed User
Longtime User
Remember to allow for the notch at the top and the "swipe up" area at the bottom of an iPhoneX screen so your ad appears properly
 
Upvote 0
Top