【发布时间】: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:包含消息初始接收者的字符串数组。
有什么方法可以检查所使用的实际邮件和收件人吗?
提前致谢!
【问题讨论】:
-
当然,如果可以使正文/收件人不可更改,那也可以。但我怀疑这是可能的吗?