0

如何从我当前的应用程序调用消息应用程序。
我知道使用此代码...

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:"]];  

或者

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:
@"sms:1-408-555-1212"]];  

但是我想要的只是调用Message App,我不想要电话号码或没有电话号码。
只想打开当前的消息应用程序视图。
请帮我....

4

2 回答 2

2
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];                    
             }

尝试这样发送消息

于 2013-03-21T04:29:43.230 回答
0

尝试这个 ::

在项目中导入MessageUI框架。

在 .h 文件中,

#import <MessageUI/MessageUI.h>

发送短信的调用方法:[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];
}

希望,它会帮助你。

谢谢。

于 2013-03-21T04:51:01.813 回答