我的一個客戶有一個問題,如果他們在特定時間之前沒有輸入作業時間,是否可以在員工應用程式中發送推送通知。
是否可以為 Android 和 iOS 應用程式創建一個服務,該服務每小時檢查一天中的時間是否已輸入資料庫,如果沒有則發送推送通知?
我不知道從哪里開始,如果可能的話。但是如果其他應用程式可以做到,那么這個應用程式也應該可以。
uj5u.com熱心網友回復:
正如@SilverWarior 建議的那樣,我創建了兩段代碼,其中一段在應用程式進入后臺時發出通知,然后當應用程式進入前臺時我清除Tnotificationcenter。我已經使用該appevent功能來觸發enterdbackgroundand willbecomeforground。
Appevent 代碼如下所示:
function TForm1.AppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.EnteredBackground:
begin
Gethourregistration(FEmployeeNr,NOW);
if dm.MthourregistrationControl.RecordCount<1 then
begin
var Notification := NotificationCenter1.CreateNotification;
try
Notification.Name := 'message1';
Notification.AlertBody := 'You have not yet entered todays hours!';
Notification.FireDate :=Date encodetime(19,0,0,0);
{ Send notification in Notification Center }
NotificationCenter1.ScheduleNotification(Notification);
Notification.Name := 'message2';
Notification.AlertBody := 'You have not yet entered todays hours!';
Notification.FireDate :=Date encodetime(21,0,0,0);
{ Send notification in Notification Center }
NotificationCenter1.ScheduleNotification(Notification);
finally
Notification.Free;
end;
end;
end;
TApplicationEvent.WillBecomeForeground:
Notificationcenter1.CancelAll;
end;
end;
我使用 OnCreate 事件請求發送通知的權限并觸發 AppEvent。
procedure TForm1.FormCreate(Sender: TObject);
var
AppEventSvc: IFMXApplicationEventService;
begin
if NotificationCenter1.AuthorizationStatus <> TAuthorizationStatus.Authorized then
begin
FPendingAction := Action;
NotificationCenter1.RequestPermission;
end;
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(AppEventSvc)) then
begin
AppEventSvc.SetApplicationEventHandler(AppEvent);
end;
end;
我已經測驗了這段代碼,對我來說,這非常有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/464440.html
