iOS Tutorial Push notifications


Old, don't use:
B4i v1.50 added support for push notifications. Push notifications feature requires some configuration.
Patience is a virtue ;)

The following steps are required inside Apple developer console:
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.
3. Create a provision file with the new App ID.

Note that you can always delete all certificates and provisions and start from scratch.

The last step is done in the IDE by clicking on Tools - Build Server - Create Push Keystore. This sends the required files to the Mac builder which then creates a file named push.keystore. This file will be used by the B4X Push Server to connect to Apple service.

Make sure to switch to HD by clicking on the small gear button:

At the end of the process the key folder should look like:



Whenever the app starts we need to register the app for remote notifications. This is done with this code:
App.RegisterUserNotifications(True, True, True) 'allow badge, sound and alert

The PushToken event will be raised with the device token. We then send the token to the push server:
Private Sub Application_PushToken (Success As Boolean, Token() As Byte)
   If Success Then
     Dim bc As ByteConverter
     Dim j As HttpJob
     j.Initialize("j", Me)
     j.PostString(ServerUrl & "/devicetoken", "token=" & bc.HexFromBytes(Token) & "&type=1")
     Log("Error getting token: " & LastException)
   End If
End Sub

Private Sub JobDone(j As HttpJob)
   If j.Success Then
     Log("Token uploaded successfully.")
     Log("Error uploading token")
   End If
End Sub

The Application_RemoteNotification event will be raised when a message arrives while the app is in the foreground. If the app is not in the foreground then a standard alert message will appear. The user can click on the message to start the app.
The Application_RemoteNotification event will be fired after the app has started.

Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
   Log("Remote notification: " & Message)
   Dim m As Map = Message.Get("aps")
End Sub

Note the new signature of Application_RemoteNotification. You should call CompletionHandler.Complete once you are done with the task related to the message. This is mainly important for silent push messages, though you should always call it.

You should use the #ProvisionFile attribute to explicitly select the push.mobileprovision file.

See also:
Apple documentation:
B4X Push Server:
Managing multiple certificates / provision files

Last edited:


Well-Known Member
Licensed User
Longtime User

Peter Yeung

Licensed User
How to create the pem file for php to send out the notification? Many thanks!

I can send out the notification through B4J push server without problem.


Active Member
Licensed User
Longtime User
Is there a way we can check at runtime if the user has granted authorization for remote notifications?



Active Member
Licensed User
Longtime User
I have lost the certificates (.pem) file that I used for sending notifications with APN HTTP/2 protocol. I remember that it took me a long way to generate it. Now I cannot find the way to get the certificate. I'm not a MAC user.

Do you have a step by step for generating the .pem file needed for http2 auth when sending notifications to APN?

Felipe Brito