当不使用应用程序时发送通知?

发布于 2025-01-22 18:33:24 字数 170 浏览 0 评论 0原文

我的一个客户的问题是,如果在一定时间之前没有进入工作时间,他们是否可以在员工应用程序中发送推送通知。

是否可以为Android和iOS应用程序创建服务,该服务是否每小时都在数据库中输入,并发送推送通知?

我不知道从哪里开始,以及是否可能。但是,如果其他应用程序可以做到,那么此应用程序也应该有可能。

A client of mine had the question of whether it is possible to send a push notification in the employee app if they have not entered their hours by a certain time.

Is it possible to create a service for Android and iOS apps that checks every hour if the hours of the day have been entered in the database, and if not then send a push notification?

I don't know where to start, and if it is possible. But if other apps can do it, it should be possible with this app as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小傻瓜 2025-01-29 18:33:24

正如@silverwarior所暗示的那样,我创建了两个代码,当应用程序进入后台时,当应用程序转到前景时,我会清理tnotificationcenter。我已经使用了Appevent函数来触发EnterDbackgroundwillbecomeforground

令人振奋的代码看起来像这样:

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;

我使用ongreate事件征求许可来发送通知并触发稳固的事件。

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;

我已经测试了此代码,对我来说,这很好。

As @SilverWarior Suggests I have created two pieces of code one makes the notifications when the app goes to the background then when the app goes to the foreground I clear Tnotificationcenter. I've used the appevent function to trigger the enterdbackground and willbecomeforground.

The Appevent code looks like this:

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;

I use the OnCreate event for asking permission for sending notifications and trigger the 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;

I have tested this code and for me, this works perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文