2010-11-03 47 views
0

在我的應用程序我用下面的代碼來處理從iPhone發送的消息我想知道如何讓他選擇與我們聯繫,並告訴朋友像其他應用程序我怎麼能使這個問題?如何讓用戶選擇郵件接收器?

代碼:

-(IBAction)sendEmail { 
    //Create a new mailComposer object and set the mailComposeDelegate (required). 
    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init]; 
    mailComposer.mailComposeDelegate = self; 

    if ([MFMailComposeViewController canSendMail]) { 

     //Set Fields such as Subject, recipients, and message body. 
     [mailComposer setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; 
     [mailComposer setSubject:@"App Feadback"]; 

     //Present the mail view controller 
     [self presentModalViewController:mailComposer animated:YES]; 
    } 

    //release the mailComposer as it is now being managed as the UIViewControllers modalViewController. 
    [mailComposer release]; 
} 

//MFMailComposeControllerDelegate method that handles success or failure 
//and dismisses the mailComposer 
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    [self dismissModalViewControllerAnimated:YES]; 

    if (result == MFMailComposeResultFailed) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Failed" message:@"Your message failed to send" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 
} 

回答

0

與我們聯繫,你必須預先填入您的郵件地址mailComposer.setToRecipient。正如你所做的那樣。

而且爲了告訴朋友,你必須在郵件作曲者之前收集你的朋友的電子郵件地址。例如使用地址簿人員選擇器控制。

無論你做什麼,MFMail作曲家都不會讓你在沒有用戶知識的情況下做任何事情。用戶可以在彈出時刪除/添加mailto字段。

+0

您好我的意思是我可以使用此代碼,但當用戶觸摸按鈕發送郵件一半窗口出現告訴朋友或與我們聯繫,然後根據他所做的選擇我會填寫此代碼(info @ ... com)或(加號==添加郵件地址) – 2010-11-03 16:34:08

+0

您可以使用UIActionSheet彈出帶有選項按鈕的半窗口。 – karim 2010-11-03 16:36:38

相關問題