I’m sure this has been discussed a lot, but I can’t find anything here.
My app is creating files (basically xml) that I need to be able to “share” or save for use in other apps. I prefer not to require users do deal with iTunes to get the files.
Likewise I need to be able to import the files to process.
I know Apple likes to keep things in the sandbox but I own a lot of apps that can save and import from the files app.
Is this possible from Xojo?
What do you recommend?
if you are sending XML to your ios app, you only have iTunes if using Windows.
You can share the documents folder with Finder on a Mac.
There is no (easily understandable?) way to get such documents from iCloud. (prove me wrong someone)
To get files OUT of your app, you can share the file with a sharing panel.
Options for sharing are to send to files, send to email, message
iCloudStuff is part of iOSKit, but I’m not sure that it works in current versions of iOS. I experienced a lot of pain with iCloud and declares so good luck getting it working. If Christian has something that works in MBS plugins you should just use than and move on.
I got it to work on a real device, with one minor modification.
Add this method to UIDocumentPickerViewController
Public Sub PresentInView(mView As MobileScreen, completion As iOSBlock = nil)
declare sub presentViewController lib UIKitLib selector "presentViewController:animated:completion:" _
(obj_id as ptr, controller as ptr, animated as Boolean, completion as ptr)
if completion <> nil then
presentViewController(mView.ViewControllerHandle, self, True, completion.Handle)
else
presentViewController(mView.ViewControllerHandle, self, True, nil)
end if
End Sub
In a MobileScreen add a browser as UIDocumentPickerViewController property.
Add the following method to the screen:
Private Sub DidPickDocument(picker As UIDocumentPickerViewController, url As NSURL)
if url <> nil then
Dim shouldBeAbleToOpen As Boolean
Select case picker.documentPickerMode
Case UIDocumentPickerViewController.UIDocumentPickerMode.Open
if url.StartAccessingSecurityScopedResource then
shouldBeAbleToOpen = True
else
break
//handle the error
end if
Case UIDocumentPickerViewController.UIDocumentPickerMode.Import
shouldBeAbleToOpen = True
End Select
If shouldBeAbleToOpen then
Dim f As new FolderItem(url.path)
try
Dim pic As Picture = Picture.Open(f)
ImageViewer1.Image = pic
Catch
MsgBox("Image error")
end try
url.StopAccessingSecurityScopedResource
Else
MsgBox("can't access image")
end if
end if
End Sub
In a Button add the following code:
//Allowed UTIs
Dim UTIs() As Text = array("public.jpeg")
//Creating the NSArray
Dim strings() As Foundation.NSString
For each u as String in UTIs
strings.Append new Foundation.NSString(u)
Next
Dim nsArr As Foundation.NSArray = Foundation.NSArray.CreateWithObjects(strings)
browser = new UIDocumentPickerViewController(nsArr, _
UIDocumentPickerViewController.UIDocumentPickerMode.Import) //.Import will tell iOS to create a copy of the file in your sandboxed app container/temp folder
//Use .Open to open the file directly
AddHandler browser.DidPickDocument, AddressOf DidPickDocument
browser.PresentInView(self)
It is not necessary to add an Entitlement for iCloud.
EDIT: Updated DidPickDocument to handle PickerMode.Open and PickerMode.Import
Both have been tested on a real device to open a JPG picture located on my iCloud Drive.
.Import mode was required to open a JPG picture located on Google Drive.
I just want to say that, Jeremie, people like you and @Jason_King and others on the forum who spend their time helping the rest of us bring non-builtin functionality to our apps are so very much appreciated! My apps simply could not do what I would want them too without you sharing your deep insight and code. I’ve already incorporated this into the app I am currently working on. So, Thank you!
Late to this party, sorry… if I try this on simulator, and log in to iCloud inside the simulator, would I expect to see the same files as I see by logging into iCloud through my desktop browser?
I’m currently trying UIDocumentPickerMBS and there seems to be no commonality between what the simulator shows, and reality.
It shows no available files in iCloud, unless I export one in the sim…