簡體   English   中英

如何用iPhone的MFMessageComposeViewController檢測SMS的實際身體和接收者?

[英]How detect actual body and recipients of SMS with MFMessageComposeViewController for iPhone?

根據我的理解,沒有辦法從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:包含郵件初始收件人的字符串數組。

有沒有辦法檢查ACTUAL消息和使用的收件人?

提前致謝!

MailComposer行為也與MessageComposer相同。 我們可以初始化內容並顯示,但是在發送或呈現控制器之后我們無法訪問任何值。 - 沒有可用的getter方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM