iOSkit add attachment question

I am beginning to learn Xojo/iOS programming (am experienced with Xojo). I need my app to email several CSV files that are stored in Specialfolder.Documents.

It appears that the native sharepanel can share just one file at a time. However, the ioskit add-on looks like it will able to share multiple files as an email attachment.

Hopefully, this is an easy question: How do you use the addAttachment function? The built-in help for that function is:

.addAttachment(attachment as xojo.IO.FolderItem, MIMEType as text, fileName as Text)

But I am new to xojo.IO.FolderItem and can’'t get past that hurdle. When I google xojo.IO.Folderitem, the documentation says it is deprecated. I guess, my question is, how do I translate the "specialfolder.documents.child(“file.csv”) into something that will work in the addattachment function?


Hi Rich,

Unfortunately iOSKit is such as beast that it hasn’t been updated for the API2 framework yet.

Not tested but this might work.
Copy-paste this code into the MFMailComposeViewController class

Public Sub addAttachment(attachment as FolderItem, MIMEType as String, fileName as String)
  declare sub addAttachment_ lib MessageUIKitLib selector "addAttachmentData:mimeType:fileName:" _
  (obj_id as ptr, data as ptr, MIMEType as CFStringRef, fileName as CFStringRef)
  addAttachment_(self,NSDataFromFolderitem(attachment), MIMEType, fileName)
End Sub

Then paste this code into the iOSKit.Extensions module

Public Function NSDataFromFolderitem(f as FolderItem) As ptr
  Declare function alloc lib FoundationLib selector "alloc" (clsRef as ptr) as ptr
  declare function dataWithContentsOfFile lib FoundationLib selector "dataWithContentsOfFile:" (clsRef as Ptr, path as CFStringRef) as Ptr
  if f = nil then
    dim r as NilObjectException = new NilObjectException
    r.Reason = "An NSData object can only be created from a valid folderitem."
    Raise r
    Return nil
  end if
  dim NSDataRef as ptr = dataWithContentsOfFile(NSClassFromString("NSData"), f.NativePath)
  Return NSDataRef
End Function

And to answer this simple question:

//f is a FolderItem
Dim ioF As new

Thanks!! I will try this!