B4i Library Firebase v3.00 + iAdMob v4.00 + Facebook 9.3

A new package with an updated Firebase and AdMob sdks is available.


The new version requires Xcode 14+
Mac: https://www.b4x.com/b4i/files/Firebase301.zip


Updates:

- iAdMob v4.0 is included in the package.
This includes implementation of UMP: https://developers.google.com/admob/ios/privacy
Note that you must add your AdMob app id:
B4X:
'Main module
#PlistExtra:<key>GADApplicationIdentifier</key>
'this is a test app id.
#PlistExtra:<string>ca-app-pub-3940256099942544~1458002511</string>

Example:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ump As UMPConsentInformation
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    ump.Initialize("ump")
    ump.Reset
'    ump.UpdateAndRequestIfNeededDebug(B4XPages.GetNativeParent(Me), Array("1A3BEBAD-587A-4600-9845-89C79B863C7D"), True)
    ump.UpdateAndRequestIfNeeded(B4XPages.GetNativeParent(Me))
    Wait For ump_Update (Success As Boolean)
    Log("success: " & Success)
    Log("canRequestAds: " & ump.CanRequestAds)
    If ump.CanRequestAds Then
        Dim ad As AdView
        ad.Initialize("ad", "ca-app-pub-3940256099942544/2934735716", B4XPages.GetNativeParent(Me), ad.SIZE_BANNER)
        If Root.Width = 0 Or Root.Height = 0 Then
            Wait For B4XPage_Resize (Width As Int, Height As Int)
        End If
        Root.AddView(ad, 0, 0, Root.Width, 50dip)
        ad.LoadAd
    End If
End Sub

Sub ad_FailedToReceiveAd (ErrorCode As String)
    Log("fail: " & ErrorCode)
End Sub

Sub ad_ReceiveAd
    Log("receive")
End Sub
 
Last edited:

Filippo

Expert
Licensed User
Longtime User
Hi Erel,

if I use this new library, then I can no longer compile, see error message.
Am I doing something wrong, or is it a bug?
 

Attachments

  • text.txt
    320.3 KB · Views: 16

Filippo

Expert
Licensed User
Longtime User
You are using Xcode 13, right? It should work with Xcode 14.
Yes, with Xcode 14 works perfectly.
Please also write this line within the first post so others don't make the same mistake I did.
 

yiankos1

Well-Known Member
Licensed User
Longtime User
iAdMob 4.00 released with updated dependencies. See first post.
I have tried the code but Wait For ump_Update (Success As Boolean) does not really waiting for a result whatever it is (consent or no-consent) and immediately logs both false.
B4X:
success: false
canRequestAds: false

UPDATE
If you use ump.UpdateAndRequestIfNeededNative(pgMain,Null) then it is waiting for a result

UPDATE 2
If you want to show IDFA message after UMP dialog then does not wait again
B4X:
Private Sub CheckIdfa
    ump.UpdateAndRequestIfNeededNative(pgMain,Null)
    Wait For ump_Update (Success As Boolean)
    Log("success: " & Success)
    Log("canRequestAds: " & ump.CanRequestAds)
 
 
    Dim no As NativeObject = Me
    no.RunMethod("requestIDFA", Null)
    Wait For GAD_TrackingAuthorization (Status As Int)
    Log("IDFA status code:" & Status)
End Sub

According to this Mobile Ads advisor, firstly we have to show UMP dialog and then IDFA, that is why i am asking

UPDATE 3
After spending my morning searching, putting this fixes the issue:
B4X:
Private Sub CheckIdfa
    ump.UpdateAndRequestIfNeededNative(pgMain,Null)
    Wait For ump_Update (Success As Boolean)
    Log("success: " & Success)
    Log("canRequestAds: " & ump.CanRequestAds)

    Sleep(0)
  
    Dim no As NativeObject = Me
    no.RunMethod("requestIDFA", Null)
    Wait For GAD_TrackingAuthorization (Status As Int)
    Log("IDFA status code:" & Status)
End Sub

UPDATE 4
It only worked once and now it does not. It drives me crazy. I need assistance
 
Last edited:

yiankos1

Well-Known Member
Licensed User
Longtime User
You can call ump.Reset to reset the consent state.
Thank you for the answer.

As mentions here:
Caution: This method is intended to be used for testing purposes only. You shouldn't call reset in production code
So we should not use reset method.

BTW, how a consent reset could help? I didn't understand the logic.

Because the main problem here is that UMP consent dialog does not wait for a selection and IDFA dialog stacks upon the other dialog.

UPDATE
If someone in the forum have the same problem, i fixed it by loading above sub "CheckIdfa" at the end of Application_Start. I was calling it from Application_Active. It is working with or without sleep(0).

It is an old project and until now i didn't transpile it to B4XPages.

I will send it for approvement and i will let you know.
 
Last edited:

ilan

Expert
Licensed User
Longtime User
hi
i have download and update all files from post # 1 but it doesnot work.

if i add this:

B4X:
   Private ump As UMPConsentInformation

i get error: B4XMainPage - 30: Unknown type: umpconsentinformation<br />Are you missing a library reference?

and in libraries i still see v3.00 and not v4.00


EDIT: sorry my mistake, i copied the xml file to the wrong place :oops:
 
Last edited:

Jack Cole

Well-Known Member
Licensed User
Longtime User
I have tried the code but Wait For ump_Update (Success As Boolean) does not really waiting for a result whatever it is (consent or no-consent) and immediately logs both false.
B4X:
success: false
canRequestAds: false

UPDATE
If you use ump.UpdateAndRequestIfNeededNative(pgMain,Null) then it is waiting for a result

UPDATE 2
If you want to show IDFA message after UMP dialog then does not wait again
B4X:
Private Sub CheckIdfa
    ump.UpdateAndRequestIfNeededNative(pgMain,Null)
    Wait For ump_Update (Success As Boolean)
    Log("success: " & Success)
    Log("canRequestAds: " & ump.CanRequestAds)
 
 
    Dim no As NativeObject = Me
    no.RunMethod("requestIDFA", Null)
    Wait For GAD_TrackingAuthorization (Status As Int)
    Log("IDFA status code:" & Status)
End Sub

According to this Mobile Ads advisor, firstly we have to show UMP dialog and then IDFA, that is why i am asking

UPDATE 3
After spending my morning searching, putting this fixes the issue:
B4X:
Private Sub CheckIdfa
    ump.UpdateAndRequestIfNeededNative(pgMain,Null)
    Wait For ump_Update (Success As Boolean)
    Log("success: " & Success)
    Log("canRequestAds: " & ump.CanRequestAds)

    Sleep(0)
 
    Dim no As NativeObject = Me
    no.RunMethod("requestIDFA", Null)
    Wait For GAD_TrackingAuthorization (Status As Int)
    Log("IDFA status code:" & Status)
End Sub

UPDATE 4
It only worked once and now it does not. It drives me crazy. I need assistance

Did you get this to work with an old app? I have one that always gives me:

B4X:
success: false
canRequestAds: false

I'm calling it at the end of Application_Start.

B4X:
    ump.Initialize("ump")
    
    #If debug
        ump.Reset
'        ump.UpdateAndRequestIfNeededDebug(Page1, Array("1A3BEBAD-587A-4600-9845-89C79B863C7D"), True)
        ump.UpdateAndRequestIfNeededNative(Page1, Null)
    #else
        ump.UpdateAndRequestIfNeeded(Page1)
    #End If
    Wait For ump_Update (Success As Boolean)
    Log("success: " & Success)
    Log("canRequestAds: " & ump.CanRequestAds)
    
    Dim no As NativeObject = Me
    no.RunMethod("requestIDFA", Null)
    Wait For GAD_TrackingAuthorization (Status As Int)

I am in the US. It seems like I would need to use: ump.UpdateAndRequestIfNeededDebug(Page1, Array("1A3BEBAD-587A-4600-9845-89C79B863C7D"), True). But if an old app requires ump.UpdateAndRequestIfNeededNative, then I can't test it. Even if it is an issue related to being in the US, I would expect canRequestAds: true. I am also running this on the simulator. Any ideas?
 

MustafaPX

Member
Licensed User
can i use this with b4i ver 8.30 ? if yes where to download the updated files 😥 sorry if my question is silly
 

Similar Threads

Top