Tag Archives: Push Notification

Delphi iOS Client Push Notification setup

Apple APNs iOS Client with Delphi 10.3+~

Prolog: A Lot is written how to implement APNs in various languages. I didn’t find, though proper one stop to learn how to implement APNs via IDERA’s Delphi. Basically, a main task with this procedure is with dealing with Apple Certifications (which is widely documented over many guides and sites).

Eventually you’d have to forge these files:

  • CertificateSigningRequest.certSigningRequest – to request a certification from Apple Services
  • Go to in Apple Developer Certification Web Console – to the AppID Identifier, and the Push Notification Capability – use the .csr to request a – And download .cer file.

    • Development SSL Certificate or
    • Production SSL Certificate
  • Use the aps_production_cert.cer – The Certification which needs to be installed in your Mac OS
    • clicking the ‘.cer’ file will add it to ‘My Certifications’ under the ‘Keys Chain’ – (Important this should appear on the ‘My Certifications’ if it isn’t there file won’t be able to get exported as a .p12)
  • Certificates.p12 – exporting the Push Certification as ‘.p12’
  • Certificates.pem – convert the ‘.p12’ file to ‘.pem’ file using openssl command:
    • openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes
  • entrust_root_certification_authority.pem – The Apple CA (it can be downloaded from
  • To test that I used the .php object (basically you can code a server using Delphi as well… but I tested that with this .php server object) from

We are using in Delphi the TMessageManager.DefaultManager class to register for various messages from the iOS APN service. Such as when registration and receiving from the system the Device TokenID. Or when this procedure fails.. http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Messaging.TMessageManager.SubscribeToMessage

And using the TiosHelper.SharedApplication to obtain the UIApplication and register the client iOS device for notifications using registerUserNotificationSettings(..); and registerForRemoteNotifications(); These procedures respond with a MessageData containing the unique device token.

uses
  // :
  FMX.Platform.iOS, System.Messaging, FMX.Platform,
  iosapi.Helpers, iOSapi.Foundation, FMX.Helpers.iOS, iOSapi.UIKit;

procedure TForm2.LogMsg(Value: String);
begin
  edtLog.Lines.Add(Value);
end;

procedure TForm2.RegisterNotificationClick(Sender: TObject);
var
  types: UIUserNotificationSettings;
begin
  // The token obtained from the TPushDeviceTokenMessage event should be used to identify the iOS client and send notifications to it
  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushDeviceTokenMessage,  procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushDeviceTokenMessage: ' + (M as TMessage<tpushdevicetokendata>).Value.Token); end);

  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushFailToRegisterMessage, procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushFailToRegisterMessage: ' + (M as TMessage<tpushfailtoregisterdata>).Value.ErrorMessage); end);

  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushRemoteNotificationMessage, procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushRemoteNotificationMessage: ' + (M as TMessage<tpushnotificationdata>).Value.Notification); end);

  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushStartupNotificationMessage, procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushStartupNotificationMessage: ' + (M as TMessage<tpushnotificationdata>).Value.Notification); end);

  types := TUIUserNotificationSettings.Wrap(TUIUserNotificationSettings.OCClass.settingsForTypes(
    UIUserNotificationTypeBadge or UIUserNotificationTypeSound or UIUserNotificationTypeAlert, nil));

  TiosHelper.SharedApplication.registerUserNotificationSettings(types);

  TiosHelper.SharedApplication.registerForRemoteNotifications();

  LogMsg('TiOSHelper.SharedApplication.registerForRemoteNotifications;');
end;

APNS – Apple Push Notification Server

I’ve updated my code on the iOS client of the “Apple Push Notification Server”. With its companion the Server side. This version of code was written in Delphi, for windows desktop environment — and I’ve enhanced it a bit. Had to understand the thingies with the signing and all the procedure.
If you are in the progress of building one yourself here are my notes on the subject:

  • Make sure you are consistent with the type of app you are developing. Basically there are two kinds: Development & Production (Distribution). What ever you choose note the following assignments:
  1. Code sign your APNS with the proper type (DEV/PRO)
  2. Assign the server to be connected to the proper gateway:
    A. gateway.sandbox.push.apple.com:2195 – for DEV
    B. gateway.push.apple.com:2195 – for PRO
  3. Make sure your type is consistent to the client side (DEV/PRO) – The type of kind will produce a different value for the client APN Token when registration the client on the server side.

I’ve created a NotificationPanel for my windows desktop machine. Yet, it isn’t as fancy as the Apple/Google ones. But it inform me on different messages that I’ve connected it to. I’ve registered it as a COM AutomationObject, so it could be used in Microsoft VBA scripts, or similar applications.

One of the features of that code is the ability to send a message via my APNS registered server.

I am still trying to figure out, why not all of the messages being sent via the APNS reach the client side. I do not know where it actually fails [Client or Server side].

In addition there is the issue with the APNS feedback system (feedback.push.apple.com:2196) which I didn’t manage to verify its function. My version of code, for it, doesn’t seems to receive and feedbacks — whether messages has been sent properly or not, and if not — what is the exact reason.