Device or Simulator?
Do you have Shared File entitlement turned on?
Should If f Is Nil Then actually say If f = Nil Then
I’m using this perfectly well (in the simulator… cant get my app onto a device at all but thats another story)
For example, for files in documents, I am doing this:
/1 Assemble a list of suitable files for a listbox data set
f = SpecialFolder.Documents
For Each f In SpecialFolder.Documents.Children
If f.Name.Right(4).Uppercase = ".TXT" Then
listoffiles.Append f.name
End If
Next
listoffiles.Sort
2/ User selects one for opening, using the list: (Thefilename is a property of the customcell)
f = SpecialFolder.Documents.child(Me.TheFileName )
If f.name.Right(4) = ".TXT" Then
GlobalMethods.LoadFile(f)
End If
3/ do something with it in my LoadFile, where tempf is the parameter name
var tis As TextInputStream
var thewholedocument as string
var tis as
If tempf <> Nil and tempf.exists Then
Try
tis = textinputstream.open(tempf)
tis.Encoding = encodings.utf8
thewholedocument = tis.ReadAll
tis.Close
Catch
End Try
end if
True.
But the code shown here has been copied over from a desktop app
(‘user cancelled’ isnt possible on iOS as there is no file selector)
‘The’ documents folder in iOS isnt available to our apps.
Only the shared one is.
So Martin must have copied files into the shared area manually.
Its possible that there is no file in the sandboxed documents folder.
(My own machine has dozens of redundant sandbox environments for simulated apps as I have tried stuff. )
Hi Greg,
You are correct the file isn’t there as when I use Jeff’s code to list the files it doesn’t appear. I have dragged the file into documents and I can see it both on the simulator and iPad. Are there multiple Documents folders?
I’m not sure how it helps me but if I drag the file into the App debug folder on the simulator it finds it and my program loads the file.
I’m not sure how a teacher would distribute their custom file so the App could find that, It would be simpler as a desktop App but then it isn’t a student mobile app
I’m assuming that when you dragged the file over, that you put it into the iCloud Documents folder. That folder is entirely different than the Documents that is associated with your app.
This is my biggest complaint about iOS apps, and I have another post about it.
‘The’ documents folder that people can save things to from (say) Apple apps, is a centralised documents area that is not available to a Xojo built iOS app.
What you CAN access is the sandboxed Documents area that is for your app only.
People can put things into it only if your app has Shared Documents entitlement,
then:
Plug the iPad into a Mac
Open the iPad as if it were a drive
Look at Files.
Find your app
Expand it, and you see the documents area
Drag files into that.
End users absolutely hate doing this, and 50% of them simply cannot achieve it.
Thanks Jeff, that must be an absolute pain for school IT admins. I managed a school with 500 Apple desktops for about 15 years but it was a breeze to handle with servers and Remote Desktop. I wonder what they do now with 1000 iPads and all the students on Mobile?
One simpler way to do it is to put your files on a web site, and give them the URL.
You can use a socket to pull text from the URL and save it locally to your app’s document folder.
Other iOS apps can be registered as the ‘owner’ of file types, so that if you get one by email, it can be ‘given’ the file by iOS
Again, that’s not possible using Xojo - it may be possible using declares.
(Probably there is something in iOSKit, but I dread having to insert that into a project - it’s huge , and (to me) impenetrable.)
Ok after a bit more research I’m guessing this just handles urls you click on from the App and you still need a socket to download. Without an example I managed to get pretty tangled up trying to use it. I can just give the user a field to enter a url and that will probably work with some checking what is coming in
Not sure if you solved this I tried to flow below.
When app starts I look for the file in documents if it is not there then I copy a file from the the copyfile location ( know it exist there because it is already created) I believe the resources from then out the file exists in the documents
Although I have been using GetResource which seems to be going away.