Send text message in iOS Xojo App

You can use our new MFMessageComposeViewControllerMBS class in MBS Xojo iOS Plugin to let the user send a text message. A dialog pops up with prefilled text and attachments, so the user can edit the message and then send it using their messages account, either using SMS or iMessage.

To handle the result, please either subclass the MFMessageComposeViewControllerMBS 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 MailComposeResultCancelled for user cancelled, MailComposeResultSent for when message is sent, MailComposeResultSaved for the message being saved for sending later or MailComposeResultFailed if it failed like being offline.

Here is some example code from our example file:

Sub Pressed()
	If MFMessageComposeViewController.canSendText Then
		
		Dim pic As Picture = LogoMBS
		Dim data As MemoryBlock = pic.ToData(picture.Formats.JPEG)
		Dim name As String = "logo.jpg"
		
		MessageComposeViewController = New MFMessageComposeViewController
		
		MessageComposeViewController.subject = "Test Message"
		MessageComposeViewController.body = "Just a test message"
		
		Call MessageComposeViewController.addAttachmentData(data, "public.jpeg", name)
		
		MessageComposeViewController.Present
	Else
		MessageBox "Can't send text."
	End If
End Sub
Class MFMessageComposeViewController Inherits MFMessageComposeViewControllerMBS
	Sub didFinishWithResult(result as Integer)
		System.DebugLog CurrentMethodName+" "+result.ToString
		Me.Dismiss
	End Sub
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.

4 Likes