Sending an iMessage as simple as possible iOS
Asked Answered
R

1

12

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.

Readily answered 1/6, 2012 at 12:19 Comment(2)
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.Maneuver
@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.Readily
G
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.

Goldeye answered 1/6, 2012 at 12:23 Comment(7)
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.Goldeye
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.Readily
Actually it is possible. I've done it before but I forgot how and I lost the code. It used CoreTelephonyReadily
Oh, I stand corrected. I found this: theiphonewiki.com/wiki/index.php?title=CoreTelephony. Looks promising.Goldeye
I've imported the framework but how do I declare it i.e. #include <>?Readily
I am learning this along with you, but I think you need to use the header file from the answer on this post: #9775419Goldeye
On iOS 12 i get "error sending message: 5". Does this work on versions 12 and above?Wera

© 2022 - 2024 — McMap. All rights reserved.