【问题标题】:Data Attachement in E-mail?电子邮件中的数据附件?
【发布时间】:2012-05-07 10:52:13
【问题描述】:

我将我的对象保存在 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 数据..

【问题讨论】:

  • 您能否详细说明可变数据的来源?如何创建实例?
  • 感谢先生回复我。我以其他方式详细发布这个问题只是访问我的个人资料..我认为你很好地理解了我的问题,我认为先生你为我建议了更好的解决方案..Thanx
  • 您可以发布问题的链接吗?我在你的个人资料中找不到它。
  • 再次感谢这里是链接先生。stackoverflow.com/questions/10479036/…

标签: iphone objective-c nsmutablearray nsdata mfmailcomposeviewcontroller


【解决方案1】:

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

看到这个

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 格式。我的数组包含 uilabel 以及所有属性。亲爱的你知道 UIlabel 属性。对于exp..textcolor.background color.text etc..no我尝试在电子邮件中发送所有这些数组数据。请为我建议更好的解决方案.thanx。
  • - (void)addAttachmentData:(NSData *)attachment mimeType:(NSString *)mimeType fileName:(NSString *)filename
  • 看看这个方法对你有没有帮助
  • 如果你有 ns 数据格式,那么为什么这个方法不适合你
【解决方案2】:

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

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

data 可以是任何你想要的,只要给出适当的 mime 类型和文件名。

【讨论】:

  • 如果数据只是文本,直接设置mime类型为text/plain,文件名后缀为.txt即可。
  • 不,先生,我的数据不仅是文本......而且它包含所有 UILabel 属性。
  • 看起来你正试图从视图属性中附加数据字节......这不是最好的方法,但你已经使用 application/octet-stream 作为 mime 类型,它应该是不可归档的NSKeyedUnarchiver,虽然 using plists 会更容易。
  • @Ash Furrow Thanx 先生。它的意思是通过这种方法我不可能通过电子邮件发送我的阵列数据。如果先生您通过这种方法看到了一些可能性,那么请指导我。因为如果我使用你建议的 plist,那么我的申请流程是 change.Thanx
  • @Ash Furrow,我有服装对象,我认为它没有存储在 plist 中。
【解决方案3】:

也许你对 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];
  } 
}

【讨论】:

  • 感谢您的回复,先生,我应用了您的方法。我将对象存储在 viewArray 中。在控制台中我看到了这个..2012-05-07 18:48:00.065 Note List[279:207 ] 测试=> 但电子邮件中没有数据显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-07
  • 2020-08-11
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
  • 2010-11-26
  • 2016-12-17
相关资源
最近更新 更多