以编程方式安排短信,而无需iPhone中的任何用户交互

时间:2013-05-06 05:25:36

标签: iphone sms schedule mfmessagecomposeview

我已经知道我们可以选择以编程方式发送短信,即使用 MFMessageComposeViewController ,但是是否可以将邮件安排到指定的收件人。我目前正在使用以下代码发送短信:

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];
    }
}

我也想知道这个代码是否适用于4.3以上版本的所有版本。截至目前,我没有可用于测试此设备的设备。所以需要一些经历过这段代码工作/失败的人的答案。

除此之外,我还想安排消息,即用户指定的日期和时间,并且该过程应该在后台运行而无需任何用户交互。

如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

使用MFMessageComposerViewController,无法在没有用户互动的情况下发送。

您可以考虑为sms网关创建自定义Web服务以实现此目的