如何从我的应用程序调用消息应用程序?
问题描述:
如何从我当前的应用程序调用消息应用程序。
我知道使用此代码...如何从我的应用程序调用消息应用程序?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:"]];
或
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:
@"sms:1-408-555-1212"]];
但我想要的只是来调用消息应用程序,我不想跟手机没有或没有电话没有。
只想打开当前消息应用程序视图。
请帮我....
答
MFMessageComposeViewController *messagComposer = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
messagComposer.messageComposeDelegate = self;
messagComposer.recipients = recipientsArray; // here give array of recipints
messagComposer.body = @"Some text";
[self presentModalViewController:picker animated:YES];
}
尝试这样发送消息
+0
不要忘记添加'MessageUI.framework' – Praveenkumar 2013-03-21 04:31:32
答
尝试在这个项目::
进口MessageUI框架。
在.h文件中,
#import <MessageUI/MessageUI.h>
调用方法forSending短信:[self SendSMS:@"YOUR_MESSAGE" recipientList:ARRAY_OF_RECIPIENTS];
这里,你没有任何收件人,然后通过数组作为nil
。
方法::
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
[controller release];
}
消息框架方法::
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
switch (result) {
case MessageComposeResultCancelled:
alert.message = @"Cancelled";
break;
case MessageComposeResultFailed:
alert.message = @"Failed";
break;
case MessageComposeResultSent:
alert.message = @"Send";
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
[alert show];
[alert release];
}
希望,它会帮助你。
谢谢。
谢谢杰克的回复。 ,但是这个也需要每次选择收件人信息,当你想发送信息。这可能是用户的麻烦。 – Chan 2013-03-21 02:42:54
为什么要启动Messages应用程序?只需使用'MFMessageComposeViewController'。您可以根据需要预先填充收件人以及邮件正文。 – rmaddy 2013-03-21 02:51:34
嗨rmaddy,谢谢你的回复。我的想法是复制并粘贴文本。而我的文字不是普通的字体。所以每次用户撰写文本后,复制它并调用Message App并粘贴它。所以用户撰写,复制,调用和粘贴。我已经完成了单击按钮组合复制。现在我需要的是使用当前视图调用短信应用程序。 – Chan 2013-03-21 02:55:04