iOS Question cant get Firebase Push Message

ykucuk

Well-Known Member
Licensed User
Longtime 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

B4X:
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 ?
 

Attachments

  • Screen Shot 2018-10-01 at 12.19.51.png
    Screen Shot 2018-10-01 at 12.19.51.png
    19.2 KB · Views: 203

tufanv

Expert
Licensed User
Longtime 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.

B4X:
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
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
Why do you need the token?
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.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime 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:
B4X:
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

I use the same sending tool with my own ApiKey.

Application_PushToken returns
B4X:
PushToken: 1
2DA645F94DB8AEB5B3D9716902A9225504110ED1CAD61009DF6AF6504977498B
Token:  ' (empty=
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
What happens when you send a message and the app is closed?

Try this:
B4X:
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
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
What happens when you send a message and the app is closed?

Try this:
B4X:
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
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.
 

Attachments

  • Screen Shot 2018-10-04 at 19.28.58.png
    Screen Shot 2018-10-04 at 19.28.58.png
    24.9 KB · Views: 195
  • Screen Shot 2018-10-04 at 19.28.47.png
    Screen Shot 2018-10-04 at 19.28.47.png
    20.3 KB · Views: 177
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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:

SS-2018-10-09_09.48.33.png


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.
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
now it works but i still can't get tokenID. how can I send a notification to this device only?
 
Upvote 0
Top