2013-03-21 57 views
0

如何從我當前的應用程序調用消息應用程序。
我知道使用此代碼...如何從我的應用程序調用消息應用程序?

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

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

但我想要的只是來調用消息應用程序,我不想跟手機沒有或沒有電話沒有。
只想打開當前消息應用程序視圖。
請幫我....

+0

謝謝傑克的回覆。 ,但是這個也需要每次選擇收件人信息,當你想發送信息。這可能是用戶的麻煩。 – Chan 2013-03-21 02:42:54

+0

爲什麼要啓動Messages應用程序?只需使用'MFMessageComposeViewController'。您可以根據需要預先填充收件人以及郵件正文。 – rmaddy 2013-03-21 02:51:34

+0

嗨rmaddy,謝謝你的回覆。我的想法是複製並粘貼文本。而我的文字不是普通的字體。所以每次用戶撰寫文本後,複製它並調用Message App並粘貼它。所以用戶撰寫,複製,調用和粘貼。我已經完成了單擊按鈕組合複製。現在我需要的是使用當前視圖調用短信應用程序。 – Chan 2013-03-21 02:55:04

回答

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

嘗試這樣發送消息

+0

不要忘記添加'MessageUI.framework' – Praveenkumar 2013-03-21 04:31:32

0

嘗試在這個項目::

進口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]; 
} 

希望,它會幫助你。

謝謝。