2

I will be grateful if someone can tell me whether it's possible to send data via SMS using the Objective-C language?

I was specifically thinking of having the user type in some info (in say an app) and then that data being sent via SMS to a server or other device where it would either be stored or the data acted on by a program.

If it is possible, what code would I need to implement?

Thank you in advance for your help.

Smiley Kot.

Mo.
  • 26,306
  • 36
  • 159
  • 225
  • 1
    This is normally what one uses the [`MFMessageComposeViewController`](https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMessageComposeViewController_class/Reference/Reference.html) class for, but this requires the user to hit a "send" button to send the message and I have a feeling you want to do this behind the scenes, without user intervention. Am I right with my guess? – Michael Dautermann Mar 03 '14 at 00:04
  • Michael, hi there! Thank you for your reply. I'm not actually looking to implement this behind the scenes. I would need the user to explicitly hit the send button. I'm still looking into MFMessageComposeViewController that you suggested but I don't think this has the capability to do what I'm looking for. Let me give you an example of what I'm looking to do. The user wishes to vote on a competition. He votes for no.2 and hits send. The data that he sends is acted on by a computer/server on the other side. I'll be grateful if you can let me know of a class that may do the above. Thanks. – user3372064 Mar 03 '14 at 03:14
  • I think this is what you are looking for https://www.twilio.com/sms/api – sbarow Mar 03 '14 at 10:32

3 Answers3

1

Their is no way to have the users phone send an SMS directly without using MFMessageComposeViewController which requires the user hit send or by using some undocumented APIs I am unaware of.

There is however a ways around this. The simplest way to do this is using SMSBroadcast or some other similar broadcasting service. However this isn't the cheapest option.

Take a look at these stack overflow posts and see if they can help lead you to a cheaper option.

how-to-send-sms-programmatically

how-to-send-text-messages-to-mobile-devices-programmatically-and-on-the-cheap

I would also suggest looking at alternative ways of sending messages. Push notifications etc.

Good luck.

Community
  • 1
  • 1
Ben Avery
  • 1,724
  • 1
  • 20
  • 33
  • Ben, thank you very much for your reply. I will look into what you have suggested. Thanks. However, just to clarify, I will require the user to hit send. So that isn't actually an issue. I just wondered whether a user can say, vote on something, then that data that he voted on, be sent to a server/computer on the other side and the data acted upon. Thank you for your help. As I say, I'll look into this. – user3372064 Mar 03 '14 at 03:17
  • Yes, you certainly can send data to a server,You wouldn't need to use SMS to achieve this. You will need to set up a server (Which can be done in a multitude of ways). Have a look at this http://stackoverflow.com/questions/16274450/how-to-send-data-from-ios-app-to-http-server. For a simple http POST example. – Ben Avery Mar 03 '14 at 03:25
  • Ben, thank you very much for your super fast reply and your help. I will look through the link you've suggested in some detail a little later. Thank you again! Wishing you a wonderful day!! – user3372064 Mar 03 '14 at 03:48
  • No worries, accept and up vote if you appreciate it :P. – Ben Avery Mar 03 '14 at 05:26
0

Use this method for sending data via SMS

MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init]; messageController.messageComposeDelegate = self;

NSData *imgData = [NSData dataWithContentsOfFile:@"Path of File"];

[messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"XYZ"];
[messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename::@"XYZ"];
[messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename::@"XYZ"];


BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"image"];

if (didAttachImage)
{
    // Present message view controller on screen
    [self presentViewController:messageController animated:YES completion:nil];
}

Good Luck !!!

Dipak Narigara
  • 1,796
  • 16
  • 18
0

Most commonly this type of system is achieved by texting a code to a short number associated with an SMS gateway.

e.g.

Text VOTE YES to 53155 to vote in the poll for .........

There is more to this than sending a SMS to a server. This will require using an SMS gateway to let the server read the SMS. This will cost you money, the server hosting will cost you as well as the SMS's costing the user.

Going for the above the only way to do this would be to use MFMessageComposeViewController as mentioned above.

However a much cheaper option (for everyone) would be to setup and webservice and just post the data rather than having the user send a text. It will just require more work on the app to build the interface and possibly some more logic.

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56