2008-10-26 45 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]; 
} 
}