Handling XLSX files in iOS TMS application

Hi all,some years ago I followed this guide iOS Tutorial | FlexCel Studio for VCL and FireMonkey documentation to enable the 'open with' on Excel file on my app, and it works great!
Now it doess't work anymore, with iOS26 and iOS27. It says 'permission denied'. I tried both from mail and from File, also debugging the path, and it seems the path is still on the app who have the file (Mail or File) and I think my app can't manage it due to sandbox restrictions.

Guide says:
Once you’ve registered your application as an app that can handle xls/x files, it will appear in the other application’s “Open in” dialogs. When the user clicks in your app icon, iOS will copy the file to /Documents/Inbox (See “A look at some of the available folders for your application” above).

This operation never happens, file is still on the old app and I cannot manage it.
I also modified my info.plist following the lateste example on the guide, but it still' doesn't work.
Do you have any idea?

Thanks
Paolo

Hi,
Thanks for reporting this. After some investigations, I believe that indeed we were mismanaging the permissions.

I still need to confirm everything (iOS is a weird thing) but:

  1. Can you try replacing in the example:
function TFormFlexView.AppHandler(AAppEvent: TApplicationEvent;
  AContext: TObject): Boolean;
begin
  Result := true;

  case AAppEvent of
   TApplicationEvent.aeOpenURL:
   begin
     Result := OpenFile(GetPhysicalPath((AContext as TiOSOpenApplicationContext).URL));
   end;
  end;
end;

with

var
  FileURL: NSURL;
  ScopedAccess: Boolean;
begin
  Result := true;

  case AAppEvent of
   TApplicationEvent.OpenURL:
   begin
     FileURL := TNSURL.Wrap(TNSURL.OCClass.URLWithString(
       StrToNSStr((AContext as TiOSOpenApplicationContext).URL)));
     if FileURL = nil then Exit(false);
     if not FileURL.isFileURL then Exit(false);

     ScopedAccess := FileURL.startAccessingSecurityScopedResource;
     try
       // Inbox files can be readable even when no security scope is granted.
       Result := OpenFile(NSStrToStr(FileURL.path));
     finally
       if ScopedAccess then FileURL.stopAccessingSecurityScopedResource;
     end;
   end;
  end;

Also, when deleting the file, check if it is in our Inbox, we shouldn't delete it if it is not ours (I believe it was always ours before, but doesn't seem to be the case anymore):

change

        finally
          TFile.Delete(aURL); //We've already read it. Now we need to delete it or it would stay forever in the inbox.
          //The file must be deleted even if it was invalid and FlexCel raised an Exception when opening it.

        end;

with

        finally
          // Remove imported Inbox copies, including invalid workbooks.
          // Cleanup failure must not discard a successfully loaded workbook.
          if IsInboxFile(aURL) then System.SysUtils.DeleteFile(aURL);

        end;

where IsInboxFile is:

function IsInboxFile(const FileName: string): Boolean;
var
  FileURL, InboxURL: NSURL;
begin
  // Only imported copies in our own Inbox belong to us. Never delete a
  // document opened in place from Files, iCloud, or another provider.
  FileURL := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(StrToNSStr(FileName)));
  InboxURL := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(
    StrToNSStr(TPath.Combine(TPath.GetDocumentsPath, 'Inbox'))));
  Result := NSStrToStr(FileURL.URLByResolvingSymlinksInPath.URLByDeletingLastPathComponent.path) =
    NSStrToStr(InboxURL.URLByResolvingSymlinksInPath.path);
end;

Seems to be working here, but I do have to check it more in depth (my ios is rusty...). I'll write more tomorrow and update the demos/tutorial when I have confirmed it. But you can check it in the meanwhile

Hi Adrian,

thanks so much, it's working as expected!

Best

Paolo