biblioteca sgcWebSockets suporta HTTP/2 protocol em Server e Client side components, Apple Push Notificações somente allows para enviar Push Notificações um partir de um Server Provider using HTTP/2 protocol, so no following articles I will show how send notificações push using biblioteca sgcWebSockets.
The Server Provider (who sends o notificações push para user's devices) requer para know which is o dispositivo token where o messages será delivered. A Device Token is um unique identifier associated para um dispositivo e application.
Using Rad Studio, você pode obter o dispositivo token id using o unit FMX.PushNotification.iOS. The concept is quite simples, o dispositivo opens um novo conexão para o apple servers e gets um DeviceToken which será used por Server provider para enviar notificações. Veja abaixo um código de exemplo para Delphi where você pode obter o Device Token.
Delphi Code
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];
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;
