Iphone 电子邮件中的数据附件?
我将对象保存在NSData格式的NSMutablearray中。不,我正在尝试将其附加到电子邮件正文中。以下是代码Iphone 电子邮件中的数据附件?,iphone,objective-c,nsmutablearray,nsdata,mfmailcomposeviewcontroller,Iphone,Objective C,Nsmutablearray,Nsdata,Mfmailcomposeviewcontroller,我将对象保存在NSData格式的NSMutablearray中。不,我正在尝试将其附加到电子邮件正文中。以下是代码 - (IBAction)sendEmail { if ([MFMailComposeViewController canSendMail]) { NSArray *recipients = [NSArray arrayWithObject:@"example@yahoo.com"]; MFMailComposeViewContr
- (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中我看到了这个..2012-05-07 15:33:22.984注释列表[273:207]测试=>]请为我建议一个更好的解决方案,如何在电子邮件正文中附加NSMutableArray数据..我不清楚您的问题,请尝试用这种方式设置数据。并在将其传递给composer之前检查要设置的值 看到这个了吗
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];
MFMailComposeViewController*picker=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
NSString*mSubject;
如果(isInvite)
{
mSubject=@“TAPP邀请”;
}
其他的
{
mSubject=@“TAPP电子邮件”;
}
[picker setSubject:MSSubject];
NSString*mBody;
如果(isInvite)
{
NSString*pTappId=[[DataModel sharedDataModel]getValueForKey:USER\u TAPP\u ID];
NSString*currentUserName=[[DataModel sharedDataModel]getValueForKey:CURRENT_USER_NAME];
mBody=[NSString stringWithFormat:@“嗨,
我们已经认识了,我希望我们能保持联系。
让我们通过TAPP()一种更智能、更私密的方式来交换和管理联系信息。
在为时已晚之前加入TAPP并保护您首选的唯一ID,然后与我联系。我的TAPP ID是%@。
有关更多信息,
考虑,
%@,pTappId,currentUserName];
}
其他的
{
mBody=[NSString stringWithFormat:@“
通过“]连接;
}
//设置收件人
NSArray*toRecipients=[NSArray数组及其对象:selectedEmailId];
//NSArray*toRecipients=[NSArray数组及其对象:@”“;
[picker setToRecipients:toRecipients];
//将图像附加到电子邮件
//NSString*path=[[NSBundle mainBundle]pathForResource:@“rainy”类型:@“png”];
//NSData*myData=UIImagePNGRepresentation(photo.image);
//[picker addAttachmentData:myData mimeType:@“image/png”文件名:@“abc.png”];
//填写电子邮件正文文本
NSString*emailBody=mBody;
[picker setMessageBody:emailBody isHTML:YES];
[自我呈现ModalviewController:picker动画:是];
[选择器释放];
我不清楚您的问题,请尝试用这种方式设置数据。并在将其传递给composer之前检查要设置的值
看到这个了吗
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];
MFMailComposeViewController*picker=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
NSString*mSubject;
如果(isInvite)
{
mSubject=@“TAPP邀请”;
}
其他的
{
mSubject=@“TAPP电子邮件”;
}
[picker setSubject:MSSubject];
NSString*mBody;
如果(isInvite)
{
NSString*pTappId=[[DataModel sharedDataModel]getValueForKey:USER\u TAPP\u ID];
NSString*currentUserName=[[DataModel sharedDataModel]getValueForKey:CURRENT_USER_NAME];
mBody=[NSString stringWithFormat:@“嗨,
我们已经认识了,我希望我们能保持联系。
让我们通过TAPP()一种更智能、更私密的方式来交换和管理联系信息。
在为时已晚之前加入TAPP并保护您首选的唯一ID,然后与我联系。我的TAPP ID是%@。
有关更多信息,
考虑,
%@,pTappId,currentUserName];
}
其他的
{
mBody=[NSString stringWithFormat:@“
通过“]连接;
}
//设置收件人
NSArray*toRecipients=[NSArray数组及其对象:selectedEmailId];
//NSArray*toRecipients=[NSArray数组及其对象:@”“;
[picker setToRecipients:toRecipients];
//将图像附加到电子邮件
//NSString*path=[[NSBundle mainBundle]pathForResource:@“rainy”类型:@“png”];
//NSData*myData=UIImagePNGRepresentation(photo.image);
//[picker addAttachmentData:myData mimeType:@“image/png”文件名:@“abc.png”];
//填写电子邮件正文文本
NSString*emailBody=mBody;
[picker setMessageBody:emailBody isHTML:YES];
[自我呈现ModalviewController:picker动画:是];
[选择器释放];
如果您试图将数据作为标准电子邮件附件附加,请使用以下方法:
NSData *data = UIImageJPEGRepresentation(artworkImageView.image, 0.0);
[picker addAttachmentData:data mimeType:@"image/jpeg" fileName:@"Photo.jpeg"];
数据可以是您想要的任何内容,只需提供适当的mime类型和文件名。如果您试图将数据作为标准电子邮件附件附加,请使用以下方法:
NSData *data = UIImageJPEGRepresentation(artworkImageView.image, 0.0);
[picker addAttachmentData:data mimeType:@"image/jpeg" fileName:@"Photo.jpeg"];
数据可以是您想要的任何内容,只需提供适当的mime类型和文件名。可能您对viewArray的定义是错误的
在.h文件中:
@property(nonatomic, retain) NSMutableArray *viewArray;
在.m文件中:
@synthesize viewArray;
请看一下apple文档中的方法“ComponentsJoinedByString”,因为我还没有找到一个错误
使用api中的viewArray初始化进行测试:(效果良好)
也许您对viewArray的定义是错误的
在.h文件中:
@property(nonatomic, retain) NSMutableArray *viewArray;
在.m文件中:
@synthesize viewArray;
请看一下apple文档中的方法“ComponentsJoinedByString”,因为我还没有找到一个错误
使用api中的viewArray初始化进行测试:(效果良好)
亲爱的,我不知道,我只想在电子邮件正文中附加我的数组数据,它是NSdata格式的。我的数组包含uilabel以及所有属性。亲爱的,你很清楚uilabel属性。对于exp..textcolor.background color.text等。不,我尝试在电子邮件中发送数组的所有数据。请为我建议更好的解决方案。thanx。-(无效)addAttachmentData:(NSData*)附件mimeType:(NSString*)mimeType文件名:(NSString*)文件名查看此方法如果对您有帮助如果您有ns数据格式,那么为什么此方法不适合您亲爱的我不知道,我只想附加我的数组数据,它是电子邮件正文中的NSdata格式。我的数组包含uilabel以及所有属性。亲爱的,你很清楚uilabel属性。对于exp..textcolor.background color.text等。不,我尝试在电子邮件中发送数组的所有数据。请