代码之家  ›  专栏  ›  技术社区  ›  Pugalmuni Tom Tharakan

如何在iPhone中创建短信应用程序

  •  2
  • Pugalmuni Tom Tharakan  · 技术社区  · 15 年前

    我是iPhone开发的新手,我想在我的应用程序中创建短消息应用程序。我已经使用“messageui.framework”创建了邮件应用程序。有没有创建短消息应用程序的框架。我不知道,请告诉我如何完成这项任务。请指导我完成任务。请帮帮我。谢谢。

    4 回复  |  直到 7 年前
        2
  •  2
  •   Brad Larson    13 年前

    as documented by Apple

    #import <MessageUI/MessageUI.h>
    #import <MessageUI/MFMessageComposeViewController.h>
    
    @interface YourViewController: UIViewController <MFMessageComposeViewControllerDelegate>
    

    - (void)viewDidLoad {
        [super viewDidLoad];
    
    SMSLabel = [[UILabel alloc] initWithFrame:CGRectMake(30.0, 340.0, 260.0, 30.0)];
        SMSLabel .frame = CGRectMake(30.0, 340.0, 260.0, 30.0);
        SMSLabel .adjustsFontSizeToFitWidth = YES;
        SMSLabel .hidden = YES;
        SMSLabel .text = @"";
        SMSLabel .userInteractionEnabled = NO;
        SMSLabel.alpha=0.0;
        [self.view addSubview:SMSLabel ];  
    
    
    }
    
    -(void)ComposerSheet 
    {
        MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
        picker.messageComposeDelegate = self;
    
        picker.recipients = [NSArray arrayWithObject:@"1234567"];  
        picker.body = @"iPhone OS4";
    
        [self presentModalViewController:picker animated:YES];
        [picker release];
    
    }
    
    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
        SMSLabel.alpha=1.0;
    
        switch (result)
        {
            case MessageComposeResultCancelled:
                SMSLabel .text = @"Result: canceled";
                NSLog(@"Result: canceled");
                break;
            case MessageComposeResultSent:
                SMSLabel .text = @"Result: sent";
                NSLog(@"Result: sent");
                break;
            case MessageComposeResultFailed:
                SMSLabel .text = @"Result: failed";
                NSLog(@"Result: failed");
                break;
            default:
                SMSLabel .text = @"Result: not sent";
                NSLog(@"Result: not sent");
                break;
        }
    
        [self dismissModalViewControllerAnimated:YES];
    
    }
    
        3
  •  1
  •   coneybeare    15 年前
        4
  •  0
  •   halfer    7 年前

        NSString *phoneToCall = @"sms:";
    NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
    NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
    [[UIApplication sharedApplication] openURL:url];