2010-06-01 36 views
0

我從iphone OS Ref Library發現了電子郵件編寫器示例代碼。這裏是一個代碼 -郵件編寫器地址問題

代碼:

NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

我的問題是如何把用戶的輸入?這裏所有的電子郵件地址都是用代碼預定義那麼,CC,密送,主題和身體字段的ID是什麼?

回答

1

使用此代碼。僅爲用戶輸入提供電子郵件地址。

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 

picker.mailComposeDelegate = self; 

NSString *msgTitle = @"Sample Title"; 

    [picker setSubject:msgTitle]; 

NSArray *toRecipients =[[NSArray alloc] init]; 

NSArray *ccRecipients =[[NSArray alloc] init]; 

NSArray *bccRecipients =[[NSArray alloc] init]; 

[picker setToRecipients:toRecipients]; 

[picker setCcRecipients:ccRecipients]; 

[picker setBccRecipients:bccRecipients]; 

    NSString *sum = @"The Email Body string is here"; 

NSString *emailBody; 

emailBody = [NSString stringWithFormat:@"%@",sum]; 

[picker setMessageBody:emailBody isHTML:YES]; 

[self presentModalViewController:picker animated:YES]; 

[picker release]; 


    -(void)launchMailAppOnDevice 
    { 
    NSString *recipients = @"mailto:?cc=,&[email protected]"; 

    NSString *body = @"&body="; 

    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body]; 

    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 

    } 

祝你好運。

+0

感謝您的回答。 我實現了代碼和它的工作順利......... – 2010-06-01 13:06:10

+0

- (無效)launchMailAppOnDevice 需要它來修改 如果是,那麼請告訴我如何把所有的陣列中的這種方法 – 2010-06-02 06:46:10

+0

@Arun夏爾馬。我認爲這種方法不需要。如果你想了解更多的細節,請參閱我更新的答案。它可能會幫助你。謝謝。 – Pugal 2010-06-02 09:18:56

1
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 
    controller.mailComposeDelegate = self; 
    [controller setToRecipients:arr]; 
    [controller setCcRecipients:arr2]; 
    [controller setBccRecipients:arr3]; 
    [controller setMessageBody:@"Hello there." isHTML:NO];