Does anybody know if it's possible, and how, to programmatically send a SMS from the iPhone
, with the official SDK / Cocoa Touch?
Join them; it only takes a minute:
|
|||||
|
RestrictionsIf you could send an SMS within a program on the iPhone, you'll be able to write games that spam people in the background. I'm sure you really want to have spams from your friends, "Try out this new game! It roxxers my boxxers, and yours will be too! roxxersboxxers.com!!!! If you sign up now you'll get 3,200 RB points!!" Apple has restrictions for automated (or even partially automated) SMS and dialing operations. (Imagine if the game instead dialed 911 at a particular time of day) Your best bet is to setup an intermediate server on the internet that uses an online SMS sending service, and send the SMSs via that route if you need complete automation. (ie, your program on the iPhone sends a UDP packet to your server, which sends the real SMS) iOS 4 UpdateiOS 4, however, now provides a viewcontroller you can import into your application. You prepopulate the SMS fields, then the user can initiate the SMS send within the controller. Unlike using the "sms:..." url format, this allows your application to stay open, and allows you to populate both the to and the body fields. You can even specify multiple recipients. This prevents applications from sending automated SMS without the user explicitly aware of it. You still cannot send fully automated SMS from the iPhone itself, it requires some user interaction. But this at least allows you to populate everything, and avoids closing the application. The MFMessageComposeViewController class is well documented, and tutorials show how easy it is to implement. iOS 5 UpdateiOS 5 includes messaging for iPod touch and iPad devices, so while I've not yet tested this myself, it may be that all iOS devices will be able to send SMS via MFMessageComposeViewController. If this is the case, then Apple is running an SMS server that sends messages on behalf of devices that don't have a cellular modem. iOS 6 UpdateNo changes to this class. iOS 7 UpdateYou can now check to see if the message medium you are using will accept a subject or attachments, and what kind of attachments it will accept. You can edit the subject and add attachments to the message, where the medium allows it. iOS 8 UpdateNo changes to this class. iOS 9 UpdateNo changes to this class. Limitations to this classKeep in mind that this won't work on phones without iOS 4, and it won't work on the iPod touch or the iPad, except, perhaps, under iOS 5. You must either detect the device and iOS limitations prior to using this controller, or risk restricting your app to recently upgraded 3G, 3GS, and 4 iPhones. However, an intermediate server that sends SMS will allow any and all of these iOS devices to send SMS as long as they have internet access, so it may still be a better solution for many applications. Alternately, use both, and only fall back to an online SMS service when the device doesn't support it. |
|||||||||||||||||||||
|
Here is a tutorial which does exactly what you are looking for: the http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/ Essentially:
And a link to the docs. |
|||||||||||||||||
|
|
|||||
|
You can use a |
||||
|
One of the systems of inter-process communication in MacOS is XPC. This system layer has been developed for inter-process communication based on the transfer of plist structures using libSystem and launchd. In fact, it is an interface that allows managing processes via the exchange of such structures as dictionaries. Due to heredity, iOS 5 possesses this mechanism as well. You might already understand what I mean by this introduction. Yep, there are system services in iOS that include tools for XPC communication. And I want to exemplify the work with a daemon for SMS sending. However, it should be mentioned that this ability is fixed in iOS 6, but is relevant for iOS 5.0—5.1.1. Jailbreak, Private Framework, and other illegal tools are not required for its exploitation. Only the set of header files from the directory /usr/include/xpc/* are needed. One of the elements for SMS sending in iOS is the system service com.apple.chatkit, the tasks of which include generation, management, and sending of short text messages. For the ease of control, it has the publicly available communication port com.apple.chatkit.clientcomposeserver.xpc. Using the XPC subsystem, you can generate and send messages without user's approval. Well, let's try to create a connection.
Now we have the XPC connection myConnection set to the service of SMS sending. However, XPC configuration provides for creation of suspended connections —we need to take one more step for the activation.
The connection is activated. Right at this moment iOS 6 will display a message in the telephone log that this type of communication is forbidden. Now we need to generate a dictionary similar to xpc_dictionary with the data required for the message sending.
Little is left: send the message to the XPC port and make sure it is delivered.
That's all. SMS sent. |
|||||
|
Add the MessageUI.Framework and use the following code
And then:
and the delegate method -
|
|||||||||
|
You can use this approach:
|
||||
|
Follow this procedures 1 .Add 2 . Import 3 . Copy this code for sending message
4 . Implement
Run And GO! |
|||||
|
|
|||||
|
There is a class in iOS 4 which supports sending messages with body and recipents from your application. It works the same as sending mail. You can find the documentation here: link text |
||||
|
//call method with name and number.
} //Method for sending message
|
||||
|
Use this:
|
||||
|
If you want, you can use the private framework |
|||||||||
|
|
|||||
|
Here is the Swift version of code to send SMS in iOS. Please noted that it only works in real devices. Code tested in iOS 7+. You can read more here. 1) Create a new Class which inherits MFMessageComposeViewControllerDelegate and NSObject:
2) How to use this class:
|
|||
|
This would be the best and short way to do it. |
||||
|
You need to use the MFMessageComposeViewController if you want to show creating and sending the message in your own app. Otherwise, you can use the sharedApplication method. |
||||
|
A lot of answers but if you really need to SmS automatically and not using the composer, you could simply call the twilio api. And here's a list with 50+ api's for sending sms from mostly any app. |
|||
|
protected by Will Oct 27 '10 at 11:29
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?