【问题标题】:How detect actual body and recipients of SMS with MFMessageComposeViewController for iPhone?如何使用 MFMessageComposeViewController for iPhone 检测 SMS 的实际正文和收件人?
【发布时间】:2011-05-26 10:32:41
【问题描述】:

据我了解,无法通过 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 应用程序中所做的更改。文档通过说

证实了这一点

body:消息的初始内容。
recipients:包含消息初始接收者的字符串数组。

有什么方法可以检查所使用的实际邮件和收件人吗?

提前致谢!

【问题讨论】:

  • 当然,如果可以使正文/收件人不可更改,那也可以。但我怀疑这是可能的吗?

标签: iphone sms


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    • 2020-12-07
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    相关资源
    最近更新 更多