【问题标题】:Mail Composer Address Problem邮件撰写者地址问题
【发布时间】:2011-02-26 06:37:02
【问题描述】:

我从 iphone OS Ref Library 中找到了电子邮件编写器示例代码。这是一个代码-

代码:

NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];

我的问题是如何接受用户的输入?这里所有的电子邮件地址都是在代码中预定义的。那么 to、CC、Bcc、subject 和 body 字段的 ID 是什么?

【问题讨论】:

    标签: iphone objective-c


    【解决方案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=,&subject=@";
    
         NSString *body = @"&body=";
    
         NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    
        email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    
      }
    

    祝你好运。

    【讨论】:

    • -(void)launchMailAppOnDevice 是否需要修改,如果是,请告诉我如何将所有数组放入此方法中
    • @Arun Sharma。我认为不需要这种方法。如果您想了解更多详细信息,请参阅我的更新答案。它可能会帮助你。谢谢。
    【解决方案2】:
    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
        controller.mailComposeDelegate = self;
        [controller setToRecipients:arr];
        [controller setCcRecipients:arr2];
        [controller setBccRecipients:arr3];
        [controller setMessageBody:@"Hello there." isHTML:NO]; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-26
      • 2020-09-24
      • 2022-11-01
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多