我已经设置了编辑器,因此已经填充了邮件正文,但将收件人留空,以便可以手动填充。
API没有我能找到的委托方法,可以让我收到有关收件人数组更改的通知。
委托方法:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result;
是在发送邮件之后调用的唯一方法,但收件人数组是空的。
有人能告诉我另一种访问此属性的方法吗?
NSString *message = [NSString stringWithFormat:@"Message"];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
//[messageController setRecipients:recipients];// This set to nil so the textfield can be filled manually and this the problem
[messageController setBody:message];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];
答案 0 :(得分:0)
我们可以初始化MessageComposer内容并显示,但遗憾的是,在呈现控制器后,我们无法获得对收件人阵列的更改或访问任何值。 - 没有可用的getter方法。
但您可以通过以下代码检查邮件是否已发送给正确的收件人并使用正确的正文:
- (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];
}