我做了一个基本的应用程序,现在只有一个按钮,你可以点击它,它会调出短信编写器(ios7 和 xcode 5)。我想我已经很好地处理了一切。模拟器不支持发送消息,所以我在手机上试了一下,但消息实际上并没有发送。您可以单击发送按钮和取消按钮,但同样,消息永远不会发送。有任何想法吗?这是我的代码:
- (IBAction)text:(UIButton *)sender {
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
[messageVC setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
NSString *smsString = [NSString stringWithFormat:@"message to send"];
messageVC.body = smsString;
messageVC.recipients = @[@"number to send to..."];
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Message was cancelled");
[self dismissViewControllerAnimated:YES completion:NULL]; break;
case MessageComposeResultFailed:
NSLog(@"Message failed");
[self dismissViewControllerAnimated:YES completion:NULL]; break;
case MessageComposeResultSent:
NSLog(@"Message was sent");
[self dismissViewControllerAnimated:YES completion:NULL]; break;
default:
break;
}
}
编辑:所以我今天早上试了一下(我一夜之间什么也没做),它奏效了。不知道是什么问题。不过谢谢!