iOS Question iAdMob Banner ?

Erel

B4X founder
Staff member
Licensed User
Longtime User
Simple banner:
B4X:
'ad is a global AdView variable
ad.Initialize("ad", "ca-app-pub-12675708333333/47443333", Page1, ad.SIZE_BANNER)
Page1.RootPanel.AddView(ad, 0, 0, 320dip, 50dip)

Sub Ad_AdScreenDismissed
   
End Sub

Sub Ad_FailedToReceiveAd (ErrorCode As String)
   Log("Failed: " & ErrorCode)
End Sub

Sub Ad_PresentScreen
   
End Sub
Sub Ad_ReceiveAd
   
End Sub

Consent: https://www.b4x.com/android/forum/threads/iadmob-and-user-consent.93381/

Adaptive size: https://www.b4x.com/android/forum/threads/admob-adaptive-banners.111896/#post-697865

You might need to set the position and size again in Page_Resize event depending on the ad location.
 
Upvote 0

ermales

Member
Licensed User
Simple banner:
B4X:
'ad is a global AdView variable
ad.Initialize("ad", "ca-app-pub-12675708333333/47443333", Page1, ad.SIZE_BANNER)
Page1.RootPanel.AddView(ad, 0, 0, 320dip, 50dip)

Sub Ad_AdScreenDismissed
 
End Sub

Sub Ad_FailedToReceiveAd (ErrorCode As String)
   Log("Failed: " & ErrorCode)
End Sub

Sub Ad_PresentScreen
 
End Sub
Sub Ad_ReceiveAd
 
End Sub

Consent: https://www.b4x.com/android/forum/threads/iadmob-and-user-consent.93381/

Adaptive size: https://www.b4x.com/android/forum/threads/admob-adaptive-banners.111896/#post-697865

You might need to set the position and size again in Page_Resize event depending on the ad location.


try to guide me in the example but I have these errors

Application_Start
Error occurred on line: 26 (MainModule)
Object was not initialized (GADBannerView)
Stack Trace: (
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 1227356
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 135616
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 1252384
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 7472
libdispatch.dylib A3849F96-1C9F-36C5-A15F-70C566F14CFF + 374288
libdispatch.dylib A3849F96-1C9F-36C5-A15F-70C566F14CFF + 377220
libdispatch.dylib A3849F96-1C9F-36C5-A15F-70C566F14CFF + 57744
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 693732
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 673240
CoreFoundation CFRunLoopRunSpecific + 464
GraphicsServices GSEventRunModal + 104
UIKitCore UIApplicationMain + 1936
B-8530-8417651B1718 + 4960
)

this is my code MAIN

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public ad As AdView

    Public App As Application
    Public NavControl As NavigationController
  
    Dim csDatosUsuario As csDatosUsuarios
    Dim res As B4XSerializator
    Dim v_ruta As String=File.DirDocuments
  
    Type Test(NumAciertosExamenTotal As Int, NumIntentosTotal As Int, NumDeVidas As Int, AvancePorcentage As Int)
    Dim myType, myType2 As Test
  
  
End Sub

Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.

  
    NavControl = Nav
  

  
    csDatosUsuario.Initialize
'    myType.Initialize
  
    If File.Exists(v_ruta, "0x0x0x0x0x0x") = False Then

        myType.Initialize

        myType.NumAciertosExamenTotal=0
        myType.NumIntentosTotal=0
        myType.NumDeVidas=0
        myType.AvancePorcentage=0
      
'        Encriptar
        Dim raf As RandomAccessFile
        raf.Initialize2(v_ruta, "0x0x0x0x0x0x", False, False)
'        raf.WriteB4XObject(myType, 0)
        raf.WriteB4XObject(res.ConvertObjectToBytes(myType), 0)
        Log("File Created")
        raf.Close
      
    End If
  

    MainModule.show
    ad.Initialize("ad", "ca-app-pub-12675708333333/47443333",MainModule.pg,ad.SIZE_BANNER)

End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
  
End Sub

Private Sub Application_Background
  
End Sub

This is my code where I want to show the banner MAINMODULE

B4X:
'Code module

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public pg As Page

    Private Label1 As Label
    Private Label2 As Label

  
End Sub

Public Sub show
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("MainLayout")
        pg.Title=""
      

'        Main.ad.Initialize("ad", "ca-app-pub-12675708333333/47443333",pg,Main.ad.SIZE_BANNER)
      
    End If
    Main.NavControl.NavigationBarVisible=False
    Main.NavControl.ShowPage(pg)
    pg.RootPanel.AddView(Main.ad, 0, 0, 320dip, 50dip)
    Sleep(4000)

  
    SimulacroModule.show
  

  
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is a mistake:
B4X:
 Dim raf As RandomAccessFile
        raf.Initialize2(v_ruta, "0x0x0x0x0x0x", False, False)
'        raf.WriteB4XObject(myType, 0)
        raf.WriteB4XObject(, 0)
No reason to use WriteB4XObject here. You are serializing the type twice.

B4X:
File.WriteBytes(..., ..., res.ConvertObjectToBytes(myType))

Initialize the ad before you call MainModule.show.
 
Upvote 0

ermales

Member
Licensed User
This is a mistake:
B4X:
 Dim raf As RandomAccessFile
        raf.Initialize2(v_ruta, "0x0x0x0x0x0x", False, False)
'        raf.WriteB4XObject(myType, 0)
        raf.WriteB4XObject(, 0)
No reason to use WriteB4XObject here. You are serializing the type twice.

B4X:
File.WriteBytes(..., ..., res.ConvertObjectToBytes(myType))

thanks, I didn't understand that part very well. now i understood
 
Last edited:
Upvote 0

ermales

Member
Licensed User
Initialize the ad before you call MainModule.show.


now i have this error

Application_Start
Error occurred on line: 61 (Main)
Object was not initialized (UIViewController)
Stack Trace: (
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 1227356
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 135616
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 1252384
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 7472
libdispatch.dylib A3849F96-1C9F-36C5-A15F-70C566F14CFF + 374288
libdispatch.dylib A3849F96-1C9F-36C5-A15F-70C566F14CFF + 377220
libdispatch.dylib A3849F96-1C9F-36C5-A15F-70C566F14CFF + 57744
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 693732
CoreFoundation 1B9B1E61-8CB4-3903-9870-402C3DE959BB + 673240
CoreFoundation CFRunLoopRunSpecific + 464
GraphicsServices GSEventRunModal + 104
UIKitCore UIApplicationMain + 1936
libdyld.dylib 2E3F4750-8B67-398B-8530-8417651B1718 + 4960
)
 
Last edited:
Upvote 0

Similar Threads

Top