Does anyone have an example of using NSFileCoordinator to access files under iCloud regimen?
Increasingly, simply trying to open or examine a file , when iCloud has been at it, can cause blocking.
Apple says use FileCoordinator to do it asynchronously, which I confess sounds hideous, but I need to give it a try
(Apple will not allow files to be excluded from iCloud, and the low-key workaround/speedup is to turn off Internet access for a while. This is not great/acceptable)
We got that wrapped in MBS Xojo Plugins: NSFileCoordinatorMBS class.
You basically make an instance, then call one of the methods and wait for the corresponding event to tell you that the file is available for read/write. This may take a while since iCloud may need to download it.
We got that wrapped
Thanks Christian, I did just find the classes. This is encouraging.
However, after many read-throughs, I cannot understand any of the documentation.
I’ll see if I can apply 'make an instance, then call one of the methods and wait ’
Edit: I cannot.
So, I made an example and used addHandler. You don’t need that as you could use a subclass instead to catch the event.
Sub Pressed() Handles Pressed
dim ofd as new OpenFileDialog
dim f as FolderItem = ofd.ShowModal(Self)
if f = nil then return
fp = new NSFilePresenterMBS
fc = new NSFileCoordinatorMBS(fp)
AddHandler fc.coordinateReadingItemAtURL, AddressOf coordinateReadingItemAtURL
// don't ask other apps to save change
dim error as NSErrorMBS
dim flags as integer = NSFileCoordinatorMBS.NSFileCoordinatorReadingWithoutChanges
fc.coordinateReadingItemAtURL(f, flags, error)
if error <> nil then
MessageBox error.localizedDescription
end if
End Sub
this picks a file and then makes a request.
And later you get the an event to read the file.
I made an example for you:
NSFileCoordinator Test.zip (5.4 KB)
2 Likes