0

I am already aware of the fact that there is an option for us to send sms programmatically i.e. using MFMessageComposeViewController, but is it possible to schedule the message to the specified recipient. I am currently using the following code to send sms:

Class smsClass = (NSClassFromString(kMessageComposer));

if(smsClass != nil && [MFMessageComposeViewController canSendText])
{
     MFMessageComposeViewController *smsSendController = [[[MFMessageComposeViewController alloc] init] autorelease];
     smsSendController.messageComposeDelegate = self;
     smsSendController.body = messageBodyView.text;
     smsSendController.recipients = [[[NSArray alloc]initWithObjects:numberField.text,nil]autorelease];
     if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 6.0)
     {
         [self presentViewController:smsSendController animated:YES completion:nil];
     }
     else
     {
         [self presentModalViewController:smsSendController animated:YES];   
     }
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{    
    switch (result) 
    {
        case MessageComposeResultCancelled:
        {
            UIAlertView *smsCancelledAlert = [[UIAlertView alloc] initWithTitle:kApp message:kCancel
                                                           delegate:self cancelButtonTitle:kOk otherButtonTitles: nil];
            [smsCancelledAlert show];
            [smsCancelledAlert release];
        }
            break;
        case MessageComposeResultFailed:
        {
            UIAlertView *smsFailedAlert = [[UIAlertView alloc] initWithTitle:kApp message:kError
                                                           delegate:self cancelButtonTitle:kOk otherButtonTitles: nil];
            [smsFailedAlert show];
            [smsFailedAlert release];
        }
            break;
        case MessageComposeResultSent:
        {
            UIAlertView *smsSentAlert = [[UIAlertView alloc]initWithTitle:kApp message:kSent delegate:self cancelButtonTitle:kOk otherButtonTitles:nil, nil];
            [smsSentAlert show];
            [smsSentAlert release]; 
        }
            break;

        default:
            break;
    }
    if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 6.0)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {
        [self dismissModalViewControllerAnimated:YES];
    }
}

I also would like to know whether this code works perfect in all versions above 4.3 till date 6.0. As of now I don't have the device available to test this. So would need some answers from some one who experienced this code as working/failed.

In addition to this, I would want to schedule the message i.e. user specified date&time and the process should be running in background without any user interaction.

How to achieve this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eshwar Chaitanya
  • 942
  • 2
  • 13
  • 34

1 Answers1

1

With MFMessageComposerViewController it is not possible to send without user interaction.

you may consider creating a custom webservice to sms gateway to do achieve this

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
  • How can I do this and is it possible to schedule sms in MFMessageComposeViewController – Eshwar Chaitanya May 06 '13 at 05:36
  • http://stackoverflow.com/questions/7715824/how-to-schedule-events-programmatically-in-ios – Lithu T.V May 06 '13 at 05:41
  • Sorry,what is here do with NSTimer,it just sets the time interval,not date and time,how can I relate this to MFMessageComposeViewController – Eshwar Chaitanya May 06 '13 at 05:54
  • I am sorry Lithu T.V,it actually worked with NSTimer,I mean initially I didn't get the idea of converting the NSDate to NSTimer,so that I can assign it in NSTimer schedule method,thanks anyway.Can you please tell me a bit about custom webservice to sms gateway,thanks :) – Eshwar Chaitanya May 06 '13 at 07:33
  • fine :) about the webservice you should create a webservice which takes inputs the mobile numbers and the message and give it to the server and at the serverside make an interface to send the messages to that mobile numbers – Lithu T.V May 06 '13 at 09:13
  • Can you give me some sample code or a good source to get started,thanks :) – Eshwar Chaitanya May 06 '13 at 10:13