在我的iPhone应用程序中,我刚刚实现了应用程序内的短信功能。短信功能正常。但是在打开MFMessageComposeViewController之后,如果用户想要取消发送短信,他们就没有选择权。剩下的唯一选择是发送短信,然后只返回上一个视图。导航栏上应该有一个取消按钮,就像它在电子邮件编辑器中一样。下面是我编写的具有应用程序内短信功能的代码行:
-(void) smsComposer{
MFMessageComposeViewController *_smsCompose = [[MFMessageComposeViewController alloc] init];
if ([MFMessageComposeViewController canSendText]) {
_smsCompose.body = @"SMS BODY";
_smsCompose.messageComposeDelegate = self;
[self presentModalViewController:_smsCompose animated:YES];
}
}
我有什么遗失的吗?
提前致谢, PC
答案 0 :(得分:6)
试试这个......
<。>文件中的
#import <MessageUI/MFMessageComposeViewController.h>
和
@interface TestViewController : UIViewController <MFMessageComposeViewControllerDelegate>
然后按下Click Click方法
-(void)buttonPressed:(UIButton *)button
{
[self sendSMS:@"Body of SMS..." recipientList:[NSArray arrayWithObjects:@"+1-111-222-3333", @"111-333-4444", nil]];
}
MFMessageComposeViewController用于创建SMS内容和另一种处理用户与SMS对话框交互的方法。
-(void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
和
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
if (result == MessageComposeResultCancelled)
NSLog(@"Message cancelled")
else if (result == MessageComposeResultSent)
NSLog(@"Message sent")
else
NSLog(@"Message failed")
}
请记住:您无法在模拟器中发送短信。在设备上测试。