iOS Question B4I 8.30 FireBase Token

fbritop

Active Member
Licensed User
Longtime User
Was there any change to the FB notifications, the way we retrieve the token?

B4X:
Public Sub Firebase_FCMConnected
    xc.Logd("fm_FCMConnected")
    xc.registerTopics
    Dim token As String=GetToken
    If token<>"" Then
        xc.logd("firebaseToken:" & token)
        kvs.Put("firebaseToken", token)
        xc.registerToken
    End If
End Sub

Private Sub GetToken As String
    Dim no As NativeObject
    Dim token As NativeObject = no.Initialize("FIRInstanceID").RunMethod("instanceID", Null).RunMethod("token", Null)
    If token.IsInitialized Then Return token.AsString Else Return ""
End Sub

This code was working OK before the update, but now it thown that the NS object was not initialized. Error is at this line:

B4X:
    Dim token As NativeObject = no.Initialize("FIRInstanceID").RunMethod("instanceID", Null).RunMethod("token", Null)

B4X:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Connected to location provider
Application_Active
fm_FCMConnected
*** mainpage: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
Application_Register
Application_Pushtoken
Error occurred on line: 618 (Main)
Object was not initialized (NSObject)
Stack Trace: (
  CoreFoundation       DD8145FF-7279-3C33-9B3F-0DA5541DD7F9 + 39472
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       DD8145FF-7279-3C33-9B3F-0DA5541DD7F9 + 975676
  LlaveMovil           -[B4IObjectWrapper object] + 108
  LlaveMovil           -[B4INativeObject RunMethod::] + 100
  LlaveMovil           -[b4i_main _gettoken] + 376
  LlaveMovil           -[b4i_main _application_pushtoken::] + 548
  CoreFoundation       DD8145FF-7279-3C33-9B3F-0DA5541DD7F9 + 458128
  CoreFoundation       DD8145FF-7279-3C33-9B3F-0DA5541DD7F9 + 128216
  LlaveMovil           +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
 LlaveMovil           -[B4IShell runMethod:] + 420
 LlaveMovil           -[B4IShell raiseEventImpl:method:args::] + 1968
 LlaveMovil           -[B4IShellBI raiseEvent:event:params:] + 1360
 LlaveMovil           __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
 libdispatch.dylib    9FA81DCE-81CF-3E8B-A1BB-FB64744769B2 + 407632
 libdispatch.dylib    9FA81DCE-81CF-3E8B-A1BB-FB64744769B2 + 411592
 libdispatch.dylib    9FA81DCE-81CF-3E8B-A1BB-FB64744769B2 + 286488
 libdispatch.dylib    9FA81DCE-81CF-3E8B-A1BB-FB64744769B2 + 285584
 CoreFoundation       DD8145FF-7279-3C33-9B3F-0DA5541DD7F9 + 604184
 CoreFoundation       DD8145FF-7279-3C33-9B3F-0DA5541DD7F9 + 488600
 CoreFoundation       CFRunLoopRunSpecific + 584
 GraphicsServices     GSEventRunModal + 160
 UIKitCore            15E101FA-5FF2-39A4-8983-3819CBA1F11D + 3626552
 UIKitCore            UIApplicationMain + 312
 LlaveMovil           main + 100
 dyld                 EB7391E7-74A5-32DD-8D17-CA86BACE9C2C + 81392
)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use this code instead of:
B4X:
Private Sub GetToken As String
    Dim FIRMessaging As NativeObject
    FIRMessaging = FIRMessaging.Initialize("FIRMessaging").GetField("messaging")
    Dim token As NativeObject = FIRMessaging.GetField("FCMToken")
    If token.IsInitialized = False Then Return "" Else Return token.AsString
End Sub
 
Last edited:
Upvote 0
Top