2010-02-12 53 views
2

我是iphone开发新手,我想在我的应用程序中创建短信应用程序。我使用“messageUI.framework”创建了邮件应用程序。是否有创建短信应用程序的任何框架。不知道它,所以告诉我接近这个任务的方式。请指导我完成我的任务。请帮助我。谢谢。如何在iPhone中创建短信应用程序

+0

对于AppStore或不? – kennytm

+0

它不适用于AppStore。 – Pugal

回答

2

遗憾之一,没有内置的视图控制器像MFMailComposeViewController电子邮件发送短信。

从iOS 4.0开始,您可以使用MFMessageComposeViewController,它是仅限电子邮件的MFMailComposeViewController的对应物。这可让您布置并发送短信。

此外,您可以使用SMS URL方案,如this question中所述。但是,看来你是这样的cannot prepopulate the body of an SMS message

1

发送消息比较简单 - 您通常可以将电子邮件发送至特殊格式的数字,例如[email protected](仅用于举例,不确定真实格式),然后发送至设备。本地不会有一种简单的方式在您的应用中接收短信。

你可以,但是,请尝试使用的许多free sms apisZeepMobile

2

您可以使用MFMessageComposeViewController类as documented by Apple

为此,首先将MessageUI.framework添加到您的项目中。

//在.h文件中进行以下更改

#import <MessageUI/MessageUI.h> 
#import <MessageUI/MFMessageComposeViewController.h> 

@interface YourViewController: UIViewController <MFMessageComposeViewControllerDelegate> 

//然后在.m文件做到以下几点。

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

} 
0

MFMessageComposeViewController将通过iMe​​ssage应用程序发送消息。但如果你想通过你的iPhone的网络生涯发送短信,那么下面的代码将帮助你

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