iOS Question cant get Firebase Push Message

Discussion in 'iOS Questions' started by ykucuk, Oct 1, 2018.

  1. ykucuk

    ykucuk Active Member Licensed User

    Hi,
    My application cant get push notification .

    -Local Mac Builder Server
    -iPhoneX on B4i-Bridge
    -b4j Sending Tool

    FCMConnected fired but there is no token code with below code

    Code:
    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 "no"


    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


    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

    LocManager.Stop

    LocManager.StopHeading

    End Sub



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

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

    Dim bc As ByteConverter

    Log(bc.HexFromBytes(Token))

    LogColor (
    "Token:" & GetToken,Colors.blue)

    'Log(LastException)

    End Sub
    Any help ?
     

    Attached Files:

  2. tufanv

    tufanv Expert Licensed User

    token code generally not become available as soon as fcm connected or pushtoken is fired so I created a timer to get the user token and when the token is finally available it stops the timer:

    timers interval is 1000 , timersayac is an int and initially equal to zero , and if can't get the token in 30 seconds then stop the timer.

    Code:
    Sub timertokencheck_tick
        timersayac=timersayac+
    1
        usertoken=GetToken
        
    If usertoken="" Then
            LogColor(
    "BULUNMADI",Colors.RED)
        
    Else
      
        timertokencheck.Enabled=
    False
     
       LogColor(
    "BULUNDU:"&gettoken,Colors.blue)
        
    End If
        
    If timersayac=30 Then
        timertokencheck.Enabled=
    False
        
    End If
    End Sub
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Why do you need the token?
     
  4. ykucuk

    ykucuk Active Member Licensed User

    Exactly I don't need a token. What I need device get push messages from "ios_general". I configured everything as a tutorial but device cant get push message.
    My Certificate and provision are valid and Adhoc.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    B4J sending tool = the tool from this post: https://www.b4x.com/android/forum/t...ions-push-messages-server-not-required.68645/
    Any other code will not work.

    What is the output of:
    Code:
    Sub Application_PushToken (Success As Boolean, Token() As Byte)

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

    Dim bc As ByteConverter

    Log(bc.HexFromBytes(Token))

    LogColor (
    "Token:" & GetToken,Colors.blue)

    'Log(LastException)

    End Sub
     
  6. ykucuk

    ykucuk Active Member Licensed User

    I use the same sending tool with my own ApiKey.

    Application_PushToken returns
    Code:
    PushToken: 1
    2DA645F94DB8AEB5B3D9716902A9225504110ED1CAD61009DF6AF6504977498B
    Token:  
    ' (empty=
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    What happens when you send a message and the app is closed?

    Try this:
    Code:
    Sub Application_PushToken (Success As Boolean, Token() As Byte)

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

    Dim bc As ByteConverter

    Log(bc.HexFromBytes(Token))
    For i = 1 To 10

    LogColor (
    "Token:" & GetToken,Colors.blue)
    Sleep(
    1000)
    Next
    'Log(LastException)

    End Sub
     
  8. ykucuk

    ykucuk Active Member Licensed User

    No. Nothing happens with the application. Not any sub or function get fired.
    I replaced the code with above code and still returns an empty string.
     

    Attached Files:

  9. Erel

    Erel Administrator Staff Member Licensed User

    You should post it as text. Not screenshot.

    Can you upload your project?
     
  10. ykucuk

    ykucuk Active Member Licensed User

    i added. Thank you
     

    Attached Files:

    • fcm.zip
      File size:
      2 KB
      Views:
      12
  11. Erel

    Erel Administrator Staff Member Licensed User

    I took your project.

    Replaced:
    1. GoogleService-Info.plist
    2. package name
    3. certificate and provision profile.

    Sent a message with the B4J code and it worked:

    [​IMG]

    I guess that the problem is in your Firebase project configuration. I recommend you to create a new Firebase project. Maybe with a different package name to make sure that you recreate everything.
     
  12. ykucuk

    ykucuk Active Member Licensed User

    thank you Erel. i will check it.
     
  13. ykucuk

    ykucuk Active Member Licensed User

    now it works but i still can't get tokenID. how can I send a notification to this device only?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for a new question or problem.
     
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