Search code examples
iosdelphifiremonkey

Hide screenshot for App Switcher in FMX iOS App


In a mobile iOS system, when double-pressing on the home button, the user will enter an App Switcher, a series of App windows will be displayed. If your own App window has sensitive info, it can be leaked at this stage.

I have managed to use FMX.Platform to catch different App events. I was trying to change to another TabItem instead of a sensitive TabItem. My code can compile, but the display on iOS still remains the same. The code looks like this:

procedure TForm1.FormCreate(Sender: TObject);
var
  aFMXApplicationEventService: IFMXApplicationEventService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then
    aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
  else
    ShowMessage('Application Event Service is not supported.');
end;

...

function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin      
  if AAppEvent = TApplicationEvent.aeWillBecomeInactive then begin
    tempActiveTbaItem := TabControl1.TabIndex;
    TabControl1.TabIndex := 4; //4 is a blank tabItem
    TabControl1.UpdateEffects;
  end else
  if AAppEvent = TApplicationEvent.aeEnteredBackground then begin
    tempActiveTbaItem := TabControl1.TabIndex;
    TabControl1.TabIndex := 4;
  end else
  if (AAppEvent = TApplicationEvent.aeBecameActive) and (tempActiveTbaItem <> -1) then begin
    TabControl1.TabIndex := 0;
  end;
    
  Result := True;
end;

I googled the web and found two solutions here:

Making sensitive data disappear in the iOS/iPadOS App Switcher

Hide Sensitive Information in the iOS App Switcher Snapshot Image

But these are for the native Xcode only. Can someone tell me how to do it in Delphi for FMX, please?


Solution

  • For iOS, this should resolve the problem:

    uses
      FMX.Platform.iOS;
    
    // Other code snipped
    
    if AAppEvent = TApplicationEvent.aeWillBecomeInactive then
    begin
      tempActiveTbaItem := TabControl1.TabIndex;
      TabControl1.TabIndex := 4; //4 is a blank tabItem
      WindowHandleToPlatform(Handle).View.setNeedsDisplay;
    end;
    

    Calling setNeedsDisplay forces the view to repaint