iOS Question ios Push Notification use token

roddy

Member
Licensed User
Longtime User
My app works fine on Android, whether I'm using a topic or a token to send push notifications.
On iOS, I only receive push notifications when using a topic. I can't receive push notifications when using a token, but I do receive a success message after sending the request.

receive message:
{
  "name": "projects/931383894864/messages/1760862324823069"
}

I checked the relevant settings:
In B4i:
#CertificateFile: ios_distribution.cer
#Entitlement: <key>aps-environment</key><string>production</string>
'APP Store provision
#ProvisionFile: hair01store.mobileprovision

In Firebase:
Use Official APN Validation Key (.P8)

Is there anything missing?
 

roddy

Member
Licensed User
Longtime User
Post the code that gets the token.
the code can get token.
Like this: "fBpE41hf3U1aleE7VT32NK:APA91bGJUZsusJWEbkX-1GU9jq6a_HU25Z4jRrw8G4ZIqNrKIZId71U4mNxUc9iYxMkGcCjwvQmoi7U3m81Bl2x5T5N8b5nzzsklUGasYcfqP6feYQsnxq8"

FirebaseMessaging:
'Code module
Sub Process_Globals
    Private fm As FirebaseMessaging
    Private FirstTime As Boolean = True
    Private xui As XUI
End Sub

Public Sub SubscribeToTopics (topic As String)
    If FirstTime Then
        FirstTime = False
        fm.Initialize("fm")
        fm.FCMConnect
        Wait For fm_FCMConnected
        Log("FCMConnected")
    End If
    fm.SubscribeToTopic(topic)
    'get token and save
    Main.Mytoken = GetToken
    Log("GetToken: " & Main.Mytoken)
    Main.SQL1.ExecNonQuery("Update user set token='" & Main.Mytoken & "' WHERE seq=1")
End Sub

Public 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

Public Sub MessageReceivedWhileInTheForeground (Message As Map)
    Log($"Message arrived while app is in the foreground: ${Message}"$)
    Dim aps As Map = Message.Get("aps")
    Dim alert As Map = aps.Get("alert")
    Log(alert.Get("body"))
    Log(alert.Get("title"))
   xui.MsgboxAsync(alert.Get("body"),alert.Get("title"))
End Sub

B4XmainPage:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "Main1")
   
    analytics.Initialize
    CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", "Mytopic")
    Main.App.RegisterUserNotifications(True, True, True)
    Main.App.RegisterForRemoteNotifications
   
End Sub
 
Last edited:
Upvote 0
Top