我的应用程序的功能之一涉及用户填写三个单独的文本字段(bookingName,Guests和date),然后使用文本编辑器通过短信通过这些字段发送文本。我很难将这些观点的内容带入正文。这是我的代码:

- (IBAction)send:(id)sender {

    MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc] init];
    [textComposer setMessageComposeDelegate:self];
    if ([MFMessageComposeViewController canSendText]) {
        [textComposer setRecipients:[NSArray arrayWithObject:@"XXXXXXX"]];
        [textComposer setBody:@"Booking Name: ,\nGuests: ,\n Date: .   "];


        [self presentViewController:textComposer animated:YES completion:NULL];
    } else {
        NSLog(@"Can't Open Text");
    }
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

{
    switch (result) {

        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;
        case MessageComposeResultFailed:
            break;
        case MessageComposeResultSent:
            break;
        default:
            break;
    }


我只是不知道在[[textComposer setBody:]部分中放什么,

我尝试了许多不同的方法,但没有效果。

谢谢你的时间!

最佳答案

首先为消息正文创建一个字符串。

NSString *body = [NSString stringWithFormat:@"Booking Name: %@,\nGuests: %@,\n Date: %@.   ", bookingName, guestCount, bookingDate];
[textComposer setBody:body];

10-05 19:08