iOS Question Firebase messaging: Token empty

Discussion in 'iOS Questions' started by ykucuk, Nov 6, 2018.

  1. ykucuk

    ykucuk Active Member Licensed User

    .Hi,

    -iPhone X
    -Adhoc Certificate
    -iOS 12.1
    -B4i v5.3

    Notification works well but i can't get tokenID from Firebase. The token is always empty.

    -Simulator
    -Adhoc Certificate
    -iOS 12.1
    -B4i v5.3

    Notification works. TokenID works.

    Any help?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Where is the code?
     
  3. ykucuk

    ykucuk Active Member Licensed User

    Code:
    'Code module

    #Region  Project Attributes 

    #ApplicationLabel: United

    #Version: 1.0.0 

    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown

    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight

    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown

    #Target: iPhone, iPad

    #ATSEnabled: True

    #MinVersion: 10

    #End Region

    #PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Used to display the current navigation data.</string>

    #PlistExtra:<key>NSLocationUsageDescription</key><string>Used to display the current navigation data.</string>

    #PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>


    #PlistExtra:<key>NSPhotoLibraryUsageDescription</key><string>Select a photo.</string>

    #PlistExtra:<key>NSCameraUsageDescription</key><string>Taking a photo.</string>

    #PlistExtra:<key>NSMicrophoneUsageDescription</key><string>Record video.</string>

    #PlistExtra:<key>NSPhotoLibraryAddUsageDescription</key><string>Save photo in albums.</string>

    #CertificateFile: ios_distribution_bahoo.cer 

    #ProvisionFile: united.mobileprovision

    #Entitlement: <key>aps-environment</key><string>production</string>

    Sub Process_Globals

    Public App As Application

    Public NavControl As NavigationController

    Private Page1 As Page

    Private analytics As FirebaseAnalytics

    Private fm As FirebaseMessaging

    End Sub



    Private Sub Application_Start (Nav As NavigationController)

    analytics.Initialize

    NavControl = Nav

    Page1.Initialize(
    "Page1")

    Page1.Title = 
    "Page 1"

    Page1.RootPanel.Color = 
    Colors.White

    NavControl.ShowPage(Page1)

    App.RegisterUserNotifications(
    TrueTrueTrue)

    App.RegisterForRemoteNotifications

    fm.Initialize(
    "fm")

    End Sub



    Private Sub fm_FCMConnected

    Log("FCMConnected")

    'here we can subscribe and unsubscribe from topics

    fm.SubscribeToTopic(
    "ios_general"'add ios_ prefix to all topics



    LogColor (GetToken, 
    Colors.Red)

    End Sub

    Sub fm_TokenRefresh(cTokenID As String)

    Log( cTokenID )

    End Sub

    Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)

    Log($"Message arrived: ${Message}"$)

    Msgbox(Message, "Push message!")

    CompletionHandler.Complete

    End Sub



    Private Sub Application_Active

    fm.FCMConnect 
    'should be called from Application_Active

    End Sub



    Private Sub Application_Background

    fm.FCMDisconnect 
    'should be called from Application_Background

    End Sub



    Sub Application_PushToken (Success As Boolean, Token() As Byte)

    Log($"PushToken: ${Success}"$)

    Log(LastException)

    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 "x"

    End Sub
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You should also post the logs.

    Try to add Sleep(5000) before getting the token. What do you need the token for?
     
  5. ykucuk

    ykucuk Active Member Licensed User

    I need token for send individual message to users.
    it works after added sleep(500)

    how can i add wait for code for sleep(500) and get token ?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Not sure that I understand the question. Make sure to watch the resumable subs video tutorial: https://b4x.com/etp.html
     
    BillMeyer likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice