Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Latest commit

 

History

History

send_an_sms_or_imessage

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
id title brief sdk
3E0CD68A-800E-A5CD-62DF-4E4DB09EF367
Send an SMS or iMessage
This recipe shows how to send an SMS or iMessage.

Recipe

To send an SMS using the UIApplication.SharedApplication.OpenUrl method, follow these steps.

  • Create an NSUrl containing the telephone number to send the SMS to:
var smsTo = NSUrl.FromString("sms:18015551234");
  • Call OpenUrl with the NSUrl:
UIApplication.SharedApplication.OpenUrl(smsTo);

The Messages application will detect if the number you requested has iMessage enabled and will automatically switch to iMessage if possible. To trigger an iMessage to an Apple ID, replace the telephone number with the Apple ID:

var imessageTo = NSUrl.FromString("sms:john@doe.com");
UIApplication.SharedApplication.OpenUrl(imessageTo);

Additional Information

The OpenUrl method returns a bool which is false if there is no application to handle the request. You can detect whether an application is present using the CanOpenUrl method like this:

var smsTo = NSUrl.FromString("sms:18015551234");
if (UIApplication.SharedApplication.CanOpenUrl(smsTo)) {
    UIApplication.SharedApplication.OpenUrl(smsTo);
} else {
    // warn the user, or hide the button...
}

You cannot specify the text that is placed in the message, nor can you force a message to be sent via code. Only the user can type and send the message.