sgcWebSockets kütüphanesi, Sunucu ve İstemci tarafı bileşenlerinde HTTP/2 protokolünü destekler; Apple Push Notifications, Push Bildirimlerini yalnızca HTTP/2 protokolü kullanan bir Sunucu Sağlayıcıdan göndermeye izin verir, bu nedenle sonraki makalelerde sgcWebSockets kütüphanesini kullanarak push bildirimlerinin nasıl gönderileceğini göstereceğim.
Sunucu Sağlayıcı (push bildirimlerini kullanıcının cihazlarına gönderen), mesajların teslim edileceği cihaz tokenının hangisi olduğunu bilmek ister. Cihaz Tokenı, bir cihaza ve uygulamaya ilişkilendirilmiş benzersiz bir tanımlayıcıdır.
Rad Studio kullanarak, cihaz tokenı kimliğini FMX.PushNotification.iOS ünitesini kullanarak edinebilirsiniz. Kavram oldukça basittir; cihaz, apple sunucularına yeni bir bağlantı açar ve Sunucu sağlayıcısı tarafından bildirim göndermek için kullanılacak bir DeviceToken edinir. Cihaz Tokenını edinebileceğiniz Delphi için bir örnek kodu aşağıda bulabilirsiniz.
Delphi Kodu
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;
