hola foro alguna idea porque no recibo la notificación push cuando la aplicación está abierta? recibo la notificación si la aplicación está cerrada o en segundo plano pero si está abierta no recibo nada
Código Delphi
[-]procedure TForminicio.FormCreate(Sender: TObject);
var
PushService: TPushService;
ServiceConnection: TPushServiceConnection;
Notifications: TArray;
const
permRead = 'android.permission.READ_EXTERNAL_STORAGE';
permWrite = 'android.permission.WRITE_EXTERNAL_STORAGE';
begin
VKAutoShowMode := TVKAutoShowMode.Always;
VertScrollBox1.OnCalcContentBounds := CalcContentBoundsProc;
PushService :=
TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.FCM);
ServiceConnection := TPushServiceConnection.Create(PushService);
ServiceConnection.Active := True;
ServiceConnection.OnChange := OnServiceConnectionChange;
ServiceConnection.OnReceiveNotification := OnReceiveNotificationEvent;
FDeviceId :=
PushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceId];
MemoLog.Lines.Add('DeviceID: ' + FDeviceId);
MemoLog.Lines.Add('Ready to receive!');
Notifications := PushService.StartupNotifications;
if Length(Notifications) > 0 then
begin
MemoLog.Lines.Add('-----------------------------------------');
MemoLog.Lines.Add('DataKey = ' + Notifications[0].DataKey);
MemoLog.Lines.Add('Json = ' + Notifications[0].Json.ToString);
MemoLog.Lines.Add('DataObject = ' +
Notifications[0].DataObject.ToString);
MemoLog.Lines.Add('-----------------------------------------');
end;
LabelID_device.Text:=FDeviceId;
end;
Código Delphi
[-]procedure TForminicio.PushEvents1PushReceived(Sender: TObject;
const AData: TPushData);
var
NC: TNotificationCenter ;
N: TNotification;
begin
MemoLog.Lines.Add('Push recibido' + lineFeed);
NC := TNotificationCenter.Create(Nil);
N := NC.CreateNotification;
try
if NC.Supported then
begin
N.Title := 'Tiene una VIsita';
N.AlertBody := AData.Message;
N.EnableSound := True;
N.Number := 1;
NC.ApplicationIconBadgeNumber := 1;
NC.PresentNotification(N);
end;
finally
NC.Free;
N.Free;
end;
end;
Código Delphi
[-]procedure TForminicio.OnServiceConnectionChange(Sender: TObject;
PushChanges: TPushService.TChanges);
var
PushService: TPushService;
begin
PushService := TPushServiceManager.Instance.GetServiceByName
(TPushService.TServiceNames.FCM);
if TPushService.TChange.DeviceToken in PushChanges then
begin
FDeviceToken := PushService.DeviceTokenValue
[TPushService.TDeviceTokenNames.DeviceToken];
MemoLog.Lines.Add('Firebase Token: ' + FDeviceToken);
LabelToken.Text:= FDeviceToken;
end;
Log.d('Firebase device token: token=' + FDeviceToken);
end;
if (TPushService.TChange.Status in PushChanges) and
(PushService.Status = TPushService.TStatus.StartupError) then
MemoLog.Lines.Add('Error: ' + PushService.StartupError);
end;
procedure TForminicio.PushEvents1DeviceRegistered(Sender: TObject);
begin
MemoLog.Lines.Add('Device Registrado:' +lineFeed);
end;
procedure TForminicio.PushEvents1DeviceTokenReceived(Sender: TObject);
begin
MemoLog.Lines.Add('Device Token recibido:' +lineFeed);
end;
procedure TForminicio.PushEvents1DeviceTokenRequestFailed(Sender: TObject;
const AErrorMessage: string);
begin
MemoLog.Lines.Add('Error:' +lineFeed);
MemoLog.Lines.Add(AErrorMessage +lineFeed);
end;
estoy desarrollando con delphi 11 y la notificaciones push en firebase