Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 3212

Push Notification in app close

$
0
0

I am using the following script to the client. Push notifications work with the application open but not closed ... The correct use will be closed with the application ...

Thank's....

unit UClient;

interface

uses

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,

FMX.Layouts, FMX.Memo, PushNotification, JSON, Androidapi.Helpers, IdIOHandler,

IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IPPeerCLient, REST.OpenSSL,

REST.Backend.BindSource, REST.Backend.PushDevice, REST.Backend.ParseProvider, REST.Backend.ParsePushDevice,

REST.Backend.ParseServices, REST.Backend.KinveyProvider, REST.Backend.ServiceComponents, REST.Backend.ServiceTypes,

REST.Backend.MetaTypes, REST.Backend.PushTypes, REST.Backend.KinveyPushDevice,

System.IOUtils, System.Devices, IdServerIOHandler;

type

TForm1 = class(TForm)

ToolBar1: TToolBar;

SpeedButton1: TSpeedButton;

SpeedButton2: TSpeedButton;

Label1: TLabel;

Memo1: TMemo;

KinveyProvider1: TKinveyProvider;

procedure SpeedButton1Click(Sender: TObject);

procedure OnChange(Sender: TObject; Achange: TPushService.Tchanges);

procedure SpeedButton2Click(Sender: TObject);

procedure OnReceiveNotificationEvent(Sender: TObject; const ANotification: TPushServiceNotification);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses

{$ifdef IOS}

FMX.PushNotification.IOS

{$else}

FMX.PushNotification.Android;

{$endif}

var

APushService : TPushService;

AServiceConnection : TPushServiceConnection;

{$R *.fmx}

procedure TForm1.OnReceiveNotificationEvent(Sender: TObject;

const ANotification: TPushServiceNotification);

begin

Memo1.Lines.Add('Data Key = '+ANotification.DataKey);

Memo1.Lines.Add('JSON = '+ANotification.Json.ToString);

Memo1.Lines.Add('Data Objetct = '+ANotification.DataObject.ToString);

end;

procedure TForm1.SpeedButton1Click(Sender: TObject);

var

ADeviceID, ADeviceToken : String;

begin

APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);

{$ifdef ANDROID}

APushService.AppProps[TPushService.TAppPropNames.GCMAppID] := 'ID MY GCM';

{$endif}

AServiceConnection := TPushServiceConnection.Create(APushService);

AServiceConnection.Active := True;

AServiceConnection.OnChange := OnChange;

AServiceConnection.OnReceiveNotification := OnReceiveNotificationEvent;

ADeviceID := APushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceID];

ADeviceToken := APushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];

// Insert memo

Memo1.Lines.Add('Device ID = '+ADeviceID);

Memo1.Lines.Add('Device Token = '+ADeviceToken);

end;

procedure TForm1.SpeedButton2Click(Sender: TObject);

begin

Memo1.Lines.Clear;

end;

procedure TForm1.OnChange(Sender: TObject; Achange: TPushService.Tchanges);

begin

Memo1.Lines.Add('OnChange');

end;

end.


Viewing all articles
Browse latest Browse all 3212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>