如何用iPhone的MFMessageComposeViewController检测SMS的实际身体和接收者?

时间:2010-12-16 09:20:39

标签: iphone sms

根据我的理解,无法从iPhone的代码发送短信。

相反,我使用MFMessageComposeViewController来显示SMS应用程序。 我之前设置了身体和接收者:

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.body = @"message";
controller.recipients = [NSArray arrayWithObject:@"phonenumber"];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];

我想确保邮件和收件人保持不变,并保持与我从代码设置的相同。 但是,用户可以在发送SMS之前更改收件人和/或邮件。

我尝试在委托方法中检查正文和收件人

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
 NSLog(@"Message: %@", controller.body);

 NSLog(@"Recipients:");
 for (NSString *recipient in controller.recipients) {
  NSLog(recipient);
 }
 switch (result) {
  case MessageComposeResultCancelled:
   NSLog(@"Result: canceled");
   break;
  case MessageComposeResultSent:
   NSLog(@"Result: sent");
   // Check that the correct message has been sent
   if([controller.body isEqualToString:correctMessage]) {
    BOOL correctRecipient = NO;
    for (NSString *recipient in controller.recipients) {
     if([recipient isEqualToString:correctRecipient]) {
      correctRecipient = YES;
     }
    }

    if(correctRecipient) {
     NSLog(@"Correct message sent to correct recipient!");
    } else {
     NSLog(@"Message or recipient was wrong");
    }
   }

   break;
  case MessageComposeResultFailed:
   NSLog(@"Result: failed");
   break;
  default:
   NSLog(@"Result: not sent");
   break;
 }

 [self dismissModalViewControllerAnimated:YES];

}

但是,controller.body和controller.recipients不会显示SMS应用程序中所做的更改。文件通过说明

来证实这一点

正文:邮件的初始内容。
recipients:包含邮件初始收件人的字符串数组。

有没有办法检查ACTUAL消息和使用过的收件人?

提前致谢!

1 个答案:

答案 0 :(得分:3)

MailComposer行为也与MessageComposer相同。我们可以初始化内容并显示,但是在发送或呈现控制器之后我们无法访问任何值。 - 没有可用的getter方法