2008-10-26 46 views

回答

1

在SDK中没有这样的东西,对不起。

5

由于您不想编写自己的SMTP客户端,您可以创建一条消息,然后通过向openURL的邮件应用程序发送URL来退出应用程序。

NSURL *url = [[NSURL alloc] initWithString: @"mailto:gilm[email protected]?subject=subject&body=body"]; 
[[UIApplication sharedApplication] openURL:url]; 

然后用户检查内容并发送消息。

+3

我的答案现在已经被修改了iPhone SDK取代。请参阅MFMailComposeViewController类。 – 2010-03-05 12:56:05

-2

正如Ben所说,不,在SDK中没有这样的东西。我的猜测是永远不会有的。我想象这个功能是在服务器端实现的,无论如何这可能是最好的选择。

2

与此同时,iPhone SDK中还包含一些新的API,包括MessageKit.framework。该框架可以添加一个MFMailComposeViewController。

希望这样的作品, 添

3

在您的.h文件导入MessageUI和MFMailComposerViewController:
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
您需要通过添加,使您的viewController MFMailComposeViewControllerDelegate:<MFMailComposeViewControllerDelegate>类似如下:

@interface tellAFriend : UIViewController <MFMailComposeViewControllerDelegate> { 


也使IBAction为告诉朋友:
​​
UPDATE
对于短信,还可以添加:
-(IBAction)tellAFriendViaSMS;


然后进入您的m,并添加以下代码:

-(IBAction)tellAFriend { 

if ([MFMailComposeViewController canSendMail]) { 

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init]; 
mailView.mailComposeDelegate = self; 
[mailView setSubject:@"Check Out your_app_name_here"]; 
[mailView setMessageBody:@"Check out your_app_name_here <br> It's really cool and I think you would like it." isHTML:YES]; 

[self presentModalViewController:mailView animated:YES]; 
[mailView release]; 

} 

else { 

NSLog(@”Mail Not Supported”); 

} 

} 

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult MFMailComposeResult)result error NSError*)error { 

[self dismissModalViewControllerAnimated:YES]; 

} 

UPDATE 您也可以使用此代码发送短信”:

-(IBAction)tellAFriendViaSMS { 
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; 
if([MFMessageComposeViewController canSendText]) 
{ 
    controller.body = @"Check Out your_app_name_here, itunes_link_here"; 
    controller.recipients = [NSArray arrayWithObjects:@"phoneNumbersHere", @"PhoneNumberTwo", nil]; // Optional 
    controller.messageComposeDelegate = self; 
    [self presentModalViewController:controller animated:YES]; 
} 
}