我是iPhone开发的新手。我想传递一些带有额外SMS细节的字符串。我正在使用以下代码将SMS发送到特定号码,但如果我想用SMS字符串发送一些数据,那么我该怎么办?谁能告诉我这种格式?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://9016098909891"]];
答案 0 :(得分:1)
SMS
网址方案未提供任何填充SMS正文的方法。因此,预先填写短信的唯一选择是使用MFMessageComposeViewController
您可以使用Messaging框架设置文本消息正文,您需要将其添加到框架中。将#import <MessageUI/MessageUI.h>
添加到导入列表。
确保视图控制器实现MFMessageComposeViewControllerDelegate
,这需要关闭MFMessageComposeViewController
。
MFMessageComposeViewControllerDelegate
的工具:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[controller dismissModalViewControllerAnimated:YES];
}
然后在显示消息编写器的方法中放置此代码:
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
messageController.body = @"Your message here.";
messageController.recipients = [NSArray arrayWithObject:@"9016098909891"];
[self presentModalViewController:messageController animated:YES];
[messageController release], messageController = nil;
答案 1 :(得分:1)
您可以在app sms功能中使用,您可以在其中设置SMS文本正文..
步骤1:将MessageUI Framework导入项目并导入头文件#import <MessageUI/MessageUI.h>
步骤2:发送短信如下
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello from Mugunth";
controller.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil];
controller.messageComposeDelegate = self;
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
}
第3步:将代表处理为
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error"
delegate:self cancelButtonTitle:@”OK” otherButtonTitles: nil];
[alert show];
[alert release];
break;
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
请参阅此处的文章http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/