Sending an iMessage as simple as possible iOS

Jordan picture Jordan · Jun 1, 2012 · Viewed 26.8k times · Source

I want to be able to programmatically send an iMessage without anything else being done except calling a function that will send a text to a number with a message, both of which are text boxes. I'd really appreciate some sample code as I've hunted the net but nothing I've found will help. This is not for a commercial app, just me so it can use Private frameworks, or anything that will do the job. Thanks.

Answer

woz picture woz · Jun 1, 2012

The only way to send a message is to the MessageUI framework. There is an example of how to do this in the iOS documentation:

https://developer.apple.com/library/ios/#samplecode/MessageComposer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010161

Edit: I just noticed this question is a duplicate of this: how to use MessageUI framework to send iMessage messages on iPhone

Correction: It appears that you can use CoreTelephony to send a message:

[[CTMessageCenter sharedMessageCenter] sendSMSWithText:message serviceCenter:nil toAddress:number];

The comment from Jordan Brown led me to this. I do suspect that this might get you banned from the App Store, but I know you said you aren't concerned with that.