« MBS Xojo Plugins, ver… | Home | Conditional Formattin… »

Send email message in iOS Xojo App

You can use our new MFMailComposeViewControllerMBS class in MBS Xojo iOS Plugin to let the user send an email message. A dialog pops up with prefilled text and attachments, so the user can edit the message and then send it using their mail account.

To handle the result, please either subclass the MFMailComposeViewControllerMBS class and implement the didFinishWithResult event. Or you use addHandler to add the event and use a method in your current screen. You get result integer, which you can compare to the constants MessageComposeResultCancelled for user cancelled, MessageComposeResultSent for when message is sent or MessageComposeResultFailed if it failed like being offline.

Here is some example code from our example file:

Sub Pressed() If MFMailComposeViewController.canSendMail Then Dim pic As Picture = LogoMBS Dim data As MemoryBlock = pic.ToData(picture.Formats.JPEG) Dim name As String = "logo.jpg" MailComposeViewController = New MFMailComposeViewController MailComposeViewController.subject = "Test Message" MailComposeViewController.setMessageBody "Just a test message", False Call MailComposeViewController.addAttachmentData(data, "image/jpeg", name) MailComposeViewController.Present Else MessageBox "Can't send email." End If End Sub
Class MFMailComposeViewController Inherits MFMailComposeViewControllerMBS
Sub didFinishWithResult(result as Integer, error as NSErrorMBS) System.DebugLog CurrentMethodName+" "+result.ToString If error <> Nil Then System.DebugLog "Error: "+error.LocalizedDescription end if Me.Dismiss End EventHandler
End Class

Please don't forget to check result code in the event and call the Dismiss method to close the dialog.

Please try the example project coming with 24.2 plugin and let us know if you have questions.

The biggest plugin in space...
12 04 24 - 08:54