11

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.

Jordan
  • 1,564
  • 2
  • 13
  • 32
  • Jordan, were you ever able to figure this out? I want to do the same and I am okay with using private APIs. I know it can be done with ChatKit.Framework but not sure how. – Zia Jan 16 '14 at 18:56
  • 1
    @user2891327 I got as far as sending an SMS but could not guarantee it would be an iMessage, I think the frameworks have changed since the and I lost my code. Sorry I can't be of more assistance, but good luck. The problem I think apple is trying to avoid (my original intention, educational purposes only) is that you could set a timer to spam somebody's iPhone essentially making a Denial Of Service (DOS) application. – Jordan Jan 19 '14 at 00:14

1 Answers1

7

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.

Community
  • 1
  • 1
woz
  • 10,888
  • 3
  • 34
  • 64
  • I know, but it isn't possible. The iOS does not allow you to access iMessage in any way, except to send SMS messages like the example does. – woz Jun 01 '12 at 12:27
  • No this question is different. I need code that will just send a message, iMessage or text because it is not up to the app but whether there is a wifi connection or not. – Jordan Jun 01 '12 at 12:28
  • Actually it is possible. I've done it before but I forgot how and I lost the code. It used CoreTelephony – Jordan Jun 01 '12 at 12:30
  • Oh, I stand corrected. I found this: http://theiphonewiki.com/wiki/index.php?title=CoreTelephony. Looks promising. – woz Jun 01 '12 at 12:45
  • I've imported the framework but how do I declare it i.e. #include <>? – Jordan Jun 01 '12 at 23:50
  • 1
    I am learning this along with you, but I think you need to use the header file from the answer on this post: http://stackoverflow.com/questions/9774919/ios-change-smsc-programmatically – woz Jun 05 '12 at 14:21
  • On iOS 12 i get "error sending message: 5". Does this work on versions 12 and above? – Martin Berger Jul 10 '19 at 12:04