How to determine the actual body and SMS recipients with MFMessageComposeViewController for iPhone?

From what I understand, there is no way to send SMS from iPhone code.

Instead, I use MFMessageComposeViewController to display the SMS application. I installed the body and recipients before:

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

I want to make sure that the message and the recipient remain intact and remain the same as I installed from the code. However, the user can change the recipients and / or message before sending the SMS.

I tried to check the body and recipients in the delegate method

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

}

However, controller.body and controller.recipients do not show the changes made to the SMS application. The documentation confirms this by saying that

body: The initial content of the message.
Recipients: an array of strings containing the original message recipients.

ACTUAL , ?

!

+3
1

MailComposer , MessageComposer. , - . -

+3

Source: https://habr.com/ru/post/1780637/


All Articles