我是iPhone开发的新手。我想传递一些带有其他SMS详细信息的字符串。我正在使用以下代码将SMS发送到特定号码,但是如果我想通过SMS字符串发送一些数据,那该怎么办?谁能告诉我这样的格式?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://9016098909891"]];
最佳答案
您可以在应用程序短信功能中使用,可以在其中设置SMS文本正文。
步骤1:将MessageUI框架导入到您的项目中,并导入头文件#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/
关于iphone - 发送短信和数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10276598/