如何在 Delphi Firemonkey 移动应用程序中检测 iOS 上的应用程序何时未从后台重新打开?

发布于 2025-01-14 02:26:33 字数 221 浏览 1 评论 0原文

我正在 Android 和 iOS 平台上开发一个 Delphi 移动应用程序,我想在应用程序首次启动时执行一些操作,但不从后台打开。

我尝试过使用 if AAppEvent <> TApplicationEvent.WillBecomeForeground 但当我第一次启动应用程序时,该声明似乎不正确。有什么方法可以让我检测应用程序何时首次启动以及应用程序何时从后台打开?

I am developing a Delphi mobile app on both Android and iOS platforms where I want to carry out some action when the app is first launched, but not open from the background.

I have tried using if AAppEvent <> TApplicationEvent.WillBecomeForeground but it seems like the statement is not true when I first launch the app. Is there any way to let me detect when the app is first launched and when the app is opened from the background?

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

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

发布评论

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

评论(1

止于盛夏 2025-01-21 02:26:33

这是示例代码:

class function TMainForm.ApplicationEventHandler(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
  if AAppEvent = TApplicationEvent.BecameActive then begin
    if fLaunchedInBackgroundState then begin
        fLaunchedInBackgroundState := False;
    end;
  end
  else if AAppEvent = TApplicationEvent.FinishedLaunching then begin
    LaunchedInBackgroundState := TiOSHelper.SharedApplication.applicationState = UIApplicationStateBackground;
  end;
end;

initialization 
  LaunchedInBackgroundState := False;
  var LAppEventSvc: IFMXApplicationEventService;
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(LAppEventSvc)) then
    LAppEventSvc.SetApplicationEventHandler(TmainForm.ApplicationEventHandler);

This is a sample code :

class function TMainForm.ApplicationEventHandler(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
  if AAppEvent = TApplicationEvent.BecameActive then begin
    if fLaunchedInBackgroundState then begin
        fLaunchedInBackgroundState := False;
    end;
  end
  else if AAppEvent = TApplicationEvent.FinishedLaunching then begin
    LaunchedInBackgroundState := TiOSHelper.SharedApplication.applicationState = UIApplicationStateBackground;
  end;
end;

initialization 
  LaunchedInBackgroundState := False;
  var LAppEventSvc: IFMXApplicationEventService;
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(LAppEventSvc)) then
    LAppEventSvc.SetApplicationEventHandler(TmainForm.ApplicationEventHandler);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文