-2

I am a IOS Developer seeking for the Messaging api in ios,I had gone through the internet and find that functionality in other possible domains as Java,php,android but,not in IOS Sector.so, can you tell me the solution for the SMS API to send message to other mobiles

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • This question has been asked before. Yes! BUT, that question is out of date. What is wrong with those down vote guys? – Yi Jiang May 27 '14 at 23:44

1 Answers1

3

Note that you can't automatically send SMS without user's knowledge. You can involve the user & then make him/her do the deed...

Sending SMS in iOS is pretty simple. You would require MFMessageComposeViewController for action. Below we have 2 delegate methods - one for composing your SMS & other when the control comes back to you after the user action.

- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
  MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
  if([MFMessageComposeViewController canSendText])
  {
    controller.body = bodyOfMessage;    
    controller.recipients = recipients;
    controller.messageComposeDelegate = self;
    [self presentModalViewController:controller animated:YES];
  }    
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
  [self dismissModalViewControllerAnimated:YES];

  if (result == MessageComposeResultCancelled)
    NSLog(@"Message cancelled")
  else if (result == MessageComposeResultSent)
    NSLog(@"Message sent")  
  else 
    NSLog(@"Message failed")  
}

There are plenty of online tutorials with full code to quick start you. Here's one. Hope this helps...

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264