FYI: Xojo 2021r3 introduces a bug when saving to SpecialFolder.Temporary in iOS

At least on the emulator, a segment of the path to the file includes what seems to be a hex-encoded message. Now, that segment is a plain text reference similar to "/(A Document Being Saved By MyApp.debug 40)/. The path is therefore invalid and the saved file cannot be access using the URLPath. Bug report has been submitted…

Confirmed.

What is the case number?

feedback://showreport?report_id=66738

The only change I can think of off the top of my head is that we’re now using the iOS 15 SDK.

My suspicion is that prior to the 15 SDK change, the folders returned by SpecialFolder.xxxxx were guaranteed to exist and that now they’re not. If that’s the case, we’ve already got a fix in for this.

1 Like

Here is a workaround until Xojo releases an update:


Dim ioF As xojo.io.FolderItem = Xojo.IO.SpecialFolder.Temporary

Dim tempfolder As FolderItem = new FolderItem(ioF.Path, FolderItem.PathModes.Native)


if tempfolder is nil then
  Break //handle this error
  Return
elseif tempfolder.Exists = False then
  try
    tempfolder.CreateFolder
  Catch err as IOException
    //Handle the error
    //This usually means the user's device storage is full
    
    Return
  end try
  
end if

//Now you can use the tempfolder

1 Like

You don’t need to do all that.

SpecialFolder.Temporary is definitely returning the path that is given to us by the OS and while the folderitem does not display the correct values in the debugger, it is fine.

Just create the file as you would expect to and then clone the folderitem like this:

Var newItem as New FolderItem(oldItem.NativePath, FolderItem.PathModes.Native)

and then use newItem.URLPath to load the file into the HTMLViewer.

Thanks all. Will try it later this morning and get back if there are problems.

Greg’s method still returned the funky path. Jeremie’s suggestion works, although the tempFolder returned does not need to be recreated in order to reach the targeted file. I modified it slightly, just in case…

Dim ioF As xojo.io.FolderItem = Xojo.IO.SpecialFolder.Temporary
Dim tempfolder As FolderItem = new FolderItem(ioF.Path, FolderItem.PathModes.Native)

if tempfolder is nil then
Break //handle this error
Return
else
if tempfolder.Exists = False then
try
tempfolder.CreateFolder
catch err as IOException
//Handle the error
//This usually means the user’s device storage is full
Return
end try
end if
end if

Thanks again…

It’s what we’re getting back from the OS so…

Greg are you implying that the path returned by Xojo.io.specialfolder.temporary is not returned by the system?
Because it is definitely different than the path returned by SpecialFolder.temporary

How about using the Parent folder for

Var f As FolderItem = FolderItem.TemporaryFile
Var tmp As Folderitem = f.parent
MessageBox(f.NativePath + Endofline + tmp.nativepath)

Is not available on iOS at the moment.

1 Like

Based on Jeremie’s idea, the following works whether the project is opened in Xojo 2021r3 or earlier:

Var htmlFolder As FolderItem = SpecialFolder.Temporary
Var htmlFile As FolderItem
Var tos As TextOutputStream

If htmlFolder.Name.IndexOf("(A Document Being") > -1 Then
Var tempFolder As Xojo.IO.FolderItem = Xojo.IO.SpecialFolder.Temporary
htmlFolder = New FolderItem(tempFolder.Path, FolderItem.PathModes.Native)
End If

htmlFile = htmlFolder.Child(“Making Billions with Xojo.html”)

If htmlFile.Exists Then htmlFile.Remove
tos = TextOutputStream.Open(htmlFile)
tos.Write html
tos.Close

HTMLViewer1.LoadURL htmlFile.URLPath

No, but Xojo.IO.SpecialFolder.Temporary calls a different method than SpecialFolder.Temporary does.

Does it return temporary folder for the curreny user or for the app?

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.