Firebase Notifications service makes it relatively easy to send push messages.
Integrating Firebase:
https://www.b4x.com/android/forum/threads/firebase-integration.68623/
Push messages in iOS requires some configuration.
1. Create a new explicit (non-wildcard)
App ID with the package name of the push app. For example anywheresoftware.b4i.push. Enable push notification service.
2. Create an Apple Push Notification SSL certificate. Use the same certSigningRequest.csr file that you previously created.
This can be done from App IDs - Choose the id - Edit.
I recommend using a Production SSL Certificate with a Distribution / Ad Hoc provision profile. This way you can use the same tokens during development and in production.
3. Create a provision file with the new App ID.
4. There should be a file named aps_*.cer in the keys folder. Now you should click on Tools - Build Server - Create Push Key - Firebase Service:
This will create a file named firebase_push.p12 in the keys folder. You need to upload it to Firebase console under Settings - CLOUD MESSAGING:
You only need to upload the production APN.
Code
The code should be similar to:
Code:
'use the distribution certificate
#CertificateFile: ios_distribution.cer
'use the provision profile that goes with the explicit App Id
#ProvisionFile: Firebase.mobileprovision
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)
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
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
Use the attached B4J (non-ui) program to send messages. It handles ios messages a bit differently. There is an assumption that all iOS topics start with ios_.