iOS Question get firebase push token

tufanv

Expert
Licensed User
Longtime User
Hello

I am trying to get individual push tokens to send individual meessages. I am using production ssl with adhoc to have same tokens during production and development. I use the code :

B4X:
Private Sub Application_Active
   fm.FCMConnect 'should be called from Application_Active
End Sub
Sub Application_PushToken (Success As Boolean, Token() As Byte)
   Log($"PushToken: ${Success}"$)
   Log("Token:" & GetToken)
   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 ""
End Sub

this returns these :

B4X:
Application_Start
Configuring the default app.
User id: CSOSZFLJI
Test device id: F09FCCFD-7732-4C20-B7FA-896C303C3F2B
Application_Active
FCMConnected
Application_Pushtoken
PushToken: 1
Token:
<B4IExceptionWrapper: (null)>
Application_Pushtoken
PushToken: 1
Token:
<B4IExceptionWrapper: (null)>

token returns 1 ( success ) but there is an error null below that and pushtoken comes null. What am i doing wrong here ?

edit: I moved the log(gettoken) code to fmc_connected as Erel advised but getting empty string still.
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
Dim token As NativeObject = no.Initialize("FIRInstanceID").RunMethod("instanceID", Null).RunMethod("token", Null)
but you already know that the ID after deleting the app is another key? Although it has nothing to do with the question, but I wanted to hint, if you have not noticed. :)
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
The problem now is , the message arrives when i run the app , but not arriving when the app is on background altough i have

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

and I have these lines:

B4X:
       App.RegisterUserNotifications(True, True, True)
   App.RegisterForRemoteNotifications
   fm.Initialize("fm")
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
It is still giving empty string but I think it is because the token is not changed so the token at first run is still valid , I am not sure about this if it is the normal behavior . I can send to that token without problem , only problem is message received when the app is on foreground. my provision profile is based on the app id and and i am using a distribution certificate with adhoc provision profile based on app id.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
by the way , when i compile the app , b4i window shows : compiled with non-store provision file. I think it is because I am using adhoc provision profile. But if I dont use adhoc provision profile , how can i test this ? I am really confused now :)
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I found the problem. I was using php to send msgs. ios needs notification field instead of data in json.

my only question in mind is : I am using adhoc distrbution provision profile and when i compile the app it says non-store provision so i cant upload it to appstore. So If i create a appstore provision profile now , and publish the app with that , will push work ? or what is the correct way to deal with this ?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I'm not sure this is the answer that can help you, but I don't care about the real token.
I subscribe to a "general" topic and to an "individual" topic using the Device_ID, so I can send general or individual notifications.
Device_ID is obtained this way

B4X:
Dim no As NativeObject
no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
IOSDeviceId=no.GetField("identifierForVendor").AsString

Note that Device_ID can change after a reinstall or system update, so the first time I get it I store it in KeyChain and alway use the same.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
thanks , I randomly create a userid and update tokens as needed , not having a problem with that. My problem is , I am using an adhoc provision profile for testing so if i change to a appstore provision profile , do i need to create everything ( firebase p12 etc ) again or am i good to go ?
 
Upvote 0
Top