APN | Register your APP with APNs

https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns

 

You must know which is the device token which identifies the user's device where you want to send the notifications. This Device Token is unique for user and device.

 

To get the device token using Rad Studio follow the next steps:

 

1. Make use in your iOS Project of FMX.PushNotification.iOS and System.PushNotification units.

2. Use TPushServiceManager class to register your application and get the device token used.

 

var
  oPushService: TPushService;
  oPushConnection: TPushServiceConnection;
begin
  oPushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.APS);
  oPushConnection := TPushServiceConnection.Create(oPushService);
  oPushConnection.Active := True;
  oPushConnection.OnChange := OnChangeEvent;
  oPushConnection.OnReceiveNotification := OnReceiveNotificationEvent;
  vDeviceId := oPushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceID];
  vDeviceToken := oPushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];
end;

procedure OnChangeEvent(Sender: TObject; AChange: TPushService.TChanges); begin   memoLog.Lines.Add('OnChange'); end;
procedure OnReceiveNotificationEvent(Sender: TObject; const ANotification: TPushServiceNotification); begin   memoLog.Lines.Add('DataKey=' + ANotification.DataKey);   memoLog.Lines.Add('JSON=' + ANotification.JSON.ToString);   memoLog.Lines.Add('DataObject=' + ANotification.DataObject.ToString); end;

The prior code basically creates a new connection with Apple Servers, when connection is fully established, returns a device token that is the value used by sgcWebSockets service provider to send notifications to this user's device.