Apple Push Notifications - Register your App (Part 1/4)

sgcWebSockets library supports HTTP/2 protocol on Server and Client side components, Apple Push Notifications only allows to send Push Notifications from a Server Provider using HTTP/2 protocol, so in the following articles I will show how send push notifications using sgcWebSockets library.

The Server Provider (who sends the push notifications to user's devices) requires to know which is the device token where the messages will be delivered. A Device Token is an unique identifier associated to a device and application. 

Using Rad Studio, you can get the device token id using the unit FMX.PushNotification.iOS. The concept is quite simple, the device opens a new connection to the apple servers and gets a DeviceToken which will be used by Server provider to send notifications. Find below a sample code for Delphi where you can get the 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; 
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Apple Push Notifications - Send HTTP/2 notificatio...
OAuth2 Client Credentials

Related Posts