0

我将我的对象保存在 NSData 格式的 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];
}

 }

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

4

3 回答 3

2

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

看到这个

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];
于 2012-05-07T10:59:49.523 回答
1

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

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

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

于 2012-05-07T11:12:47.703 回答
1

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

在您的 .h 文件中:

@property(nonatomic, retain) NSMutableArray *viewArray;

在您的 .m 文件中:

@synthesize viewArray;

请查看方法“componentsJoindedByString”的苹果文档,因为我找不到非常清楚的错误。

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

- (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];
  } 
}
于 2012-05-07T11:54:55.470 回答