2012-03-15 16 views

答えて

0
import 
#import <MessageUI/MessageUI.h> 


<MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate> 



    -(void)send_SMS{ 

     Class messageClass = (NSClassFromString(@"MFMessageComposeViewController")); 

      if (messageClass != nil) { 
       // Check whether the current device is configured for sending SMS messages 
       if ([messageClass canSendText]) { 
        [self displaySMSComposerSheet]; 
       } 
       else { 
        // feedbackMsg.hidden = NO; 
        // feedbackMsg.text = @"Device not configured to send SMS."; 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device not configured to send SMS." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call",nil]; 
        //[alert setTag:5]; 
        [alert show]; 
       } 
      } 
      else { 
       // feedbackMsg.hidden = NO; 
       // feedbackMsg.text = @"Device not configured to send SMS."; 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device not configured to send SMS." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call",nil]; 
       //[alert setTag:5]; 
       [alert show]; 

      } 


    } 




// Displays an SMS composition interface inside the application. 
-(void)displaySMSComposerSheet 
{ 
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; 
    picker.messageComposeDelegate = self; 
    [email protected]"Testing"; 
    picker.recipients = [NSArray arrayWithObject:@"12345678"]; 
    [self presentModalViewController:picker animated:YES]; 
    } 



// Dismisses the message composition interface when users tap Cancel or Send. Proceeds to update the 
// feedback message field with the result of the operation. 
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
       didFinishWithResult:(MessageComposeResult)result { 

    feedbackMsg.hidden = NO; 
    // Notifies users about errors associated with the interface 
    switch (result) 
    { 
     case MessageComposeResultCancelled:{ 
      //feedbackMsg.text = @"Result: SMS sending canceled"; 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS sending canceled" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
      break; 
     case MessageComposeResultSent:{ 
      //feedbackMsg.text = @"Result: SMS sent"; 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
      break; 
     case MessageComposeResultFailed:{ 
      //feedbackMsg.text = @"Result: SMS sending failed"; 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS sending failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
      break; 
     default: 
     { 
      //feedbackMsg.text = @"Result: SMS not sent"; 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS not sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
      break; 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
}