电子邮件中的数据附加



我将我的对象保存在 NSData formate 的 NSMutablearray 中。不,我尝试在电子邮件正文中附加,这是代码。

  - (IBAction)sendEmail
     {
   if ([MFMailComposeViewController canSendMail])
  {
       NSArray *recipients = [NSArray arrayWithObject:@"example@yahoo.com"];
       MFMailComposeViewController *controller = [[MFMailComposeViewController 
            alloc] init];
       controller.mailComposeDelegate = self;
       [controller setSubject:@"Iphone Game"];
       NSString *string = [viewArray componentsJoinedByString:@"n"];
       NSString *emailBody = string; 
       NSLog(@"test=%@",emailBody);
       [controller setMessageBody:emailBody isHTML:YES];
       [controller setToRecipients:recipients];
       [self presentModalViewController:controller animated:YES];
       [controller release];
    }
else 
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" 
            message:@"Your device is not set up for email." delegate:self 
            cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];   
    [alert release];
}
 }

我没有收到任何错误,但在 NSLog E-mail.in 看不到任何数据,我看到这个。.2012-05-07 15:33:22.984 注释列表[273:207] test=>]请为我建议任何更好的解决方案,如何在电子邮件正文中附加NSMutableArray数据。

我不清楚你的问题,尝试这种方式来设置你的数据。 并在将其传递给作曲家之前检查要设置的值,

看到这里

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    NSString *mSubject;
    if(isInvite)
    {
        mSubject=@"TAPP Invitation";
    }
    else 
    {
        mSubject= @"TAPP email";
    }
    [picker setSubject:mSubject];
    NSString *mBody;
    if(isInvite)
    {
        NSString *pTappId=[[DataModel sharedDataModel] getValueForKey:USER_TAPP_ID];
        NSString *currentUserName=[[DataModel sharedDataModel] getValueForKey:CURRENT_USER_NAME];
         mBody=[NSString stringWithFormat:@"<HTML><BODY>Hi,<br><br>We already know one another, and I would like us to keep in touch.<br><br>Let's connect through TAPP (<a href="http://download.mytapp.com">Download Here</a>) a smarter, private way to exchange and manage contact information.<br><br>Join TAPP and secure your preferred, unique ID before it is too late, and then connect with me. My TAPP ID is %@.<br><br>For more information, <a href="http://www.mytapp.com">click here</a><br><br>Regards,<br><br>%@</BODY></HTML>",pTappId,currentUserName];
    }
    else 
    {
        mBody= [NSString stringWithFormat:@"<HTML><BODY><br /><br />Connected by <a href=http://www.mytapp.com>TAPP</a></BODY></HTML>"];
    }
    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:selectedEmailId]; 
    //NSArray *toRecipients = [NSArray arrayWithObject:@""]; 
    [picker setToRecipients:toRecipients];
    // Attach an image to the email
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
    //NSData *myData = UIImagePNGRepresentation(photo.image);
    //[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"abc.png"];
    // Fill out the email body text
    NSString *emailBody = mBody;
    [picker setMessageBody:emailBody isHTML:YES];
    [self presentModalViewController:picker animated:YES];
    [picker release];

如果您尝试将数据附加为标准电子邮件附件,请使用以下命令:

NSData *data = UIImageJPEGRepresentation(artworkImageView.image, 0.0);
[picker addAttachmentData:data mimeType:@"image/jpeg" fileName:@"Photo.jpeg"];

data可以是您想要的任何内容,只需提供适当的 MIME 类型和文件名即可。

也许你对viewArray的定义是错误的?

在您的 .h 文件中:

@property(nonatomic, retain) NSMutableArray *viewArray;

在 .m 文件中:

@synthesize viewArray;

请查看方法"componentsJoindedByString"的苹果文档,因为我找不到错误。

我使用 viewArray 从 API 初始化的测试:(效果很好)

- (IBAction)sendEmail {
  self.viewArray = [NSArray arrayWithObjects:@"here", @"be", @"dragons", nil];
  if ([MFMailComposeViewController canSendMail])
  {
    NSArray *recipients = [NSArray arrayWithObject:@"example@yahoo.com"];
    MFMailComposeViewController *controller = [[MFMailComposeViewController 
                                            alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"Iphone Game"];
    //is anything in the array?
    NSLog(@"viewArray: %@", viewArray);
    NSString *string = [viewArray componentsJoinedByString:@"n"];
    NSString *emailBody = string; 
    NSLog(@"test=%@",emailBody);
    [controller setMessageBody:emailBody isHTML:YES];
    [controller setToRecipients:recipients];
    [self presentModalViewController:controller animated:YES];
    [controller release];
  }
  else 
  { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" 
                                                message:@"Your device is not set up for     email." delegate:self 
                                      cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];   
    [alert release];
  } 
}

相关内容

最新更新