iphonesmsschedulemfmessagecomposeviewcontroller

Schedule sms programmatically with out any user interaction in iPhone


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?


Solution

  • 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