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;

Leave a Reply

Your email address will not be published. Required fields are marked *