附件不包括';t显示在通过iPhone发送的邮件中
我已经通过iPhone应用程序发送了附件 但是,当我看到邮件时,我可以看到upin,它显示有附件 但是当我打开邮件时,我找不到任何附件 这背后的问题是什么附件不包括';t显示在通过iPhone发送的邮件中,iphone,xcode,email,attachment,Iphone,Xcode,Email,Attachment,我已经通过iPhone应用程序发送了附件 但是,当我看到邮件时,我可以看到upin,它显示有附件 但是当我打开邮件时,我找不到任何附件 这背后的问题是什么 -(IBAction)btnPressedExport:(id)sender{ NSArray *x=[[NSArray alloc] initWithArray:[DatabaseAccess getAllTransactionsForUserID:[BudgetTrackerAppDelegate getUserID] prof
-(IBAction)btnPressedExport:(id)sender{
NSArray *x=[[NSArray alloc] initWithArray:[DatabaseAccess getAllTransactionsForUserID:[BudgetTrackerAppDelegate getUserID] profileID:[BudgetTrackerAppDelegate getProfileID]]];
int i=-1,j=[x count];
NSDictionary *tmp;
NSMutableString *stringToWrite=[[NSMutableString alloc] init];
for(;i<j;i++){
if(i==-1){
[stringToWrite appendString:@"TransactionID,TransactionDate,ProfileName,ProfileType,GroupName,GroupType,CategoryName,TransactionAmt\n"];
} else {
tmp=[x objectAtIndex:i];
[stringToWrite appendFormat:@"%@,%@,%@,%@,%@,%@,%@,%@\n",
[tmp valueForKey:@"TraID"],[tmp valueForKey:@"TraDate"],[tmp valueForKey:@"ProfileName"],[tmp valueForKey:@"ProfileType"],[tmp valueForKey:@"GroupName"],[tmp valueForKey:@"GroupType"],[tmp valueForKey:@"CatName"],[tmp valueForKey:@"TraAmt"]];
}
}
[stringToWrite writeToFile:[self pathOfCSVForExport] atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
// [stringToWrite writeToFile:[self pathOfCSVForExport] atomically:YES];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate=self;
// picker.delegate=self;
[picker setSubject:@"Hello from Sugar!"];
//Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"sugar.srk@pqr.com"];
// NSArray *ccRecipients = [NSArray arrayWithObjects:@"xyz.dalal@pqr.com", @"kandarp.dave@phptalent.com", nil];
// NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
// [picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"myExport" ofType:@"csv"];
NSData *myData = [NSData dataWithContentsOfFile:path];
NSString *fileNameToSend=@"BudgetTracker.csv";//[NSString stringWithFormat:@"%@.csv",[x valueForKey:@"ProfileName"]];
[picker addAttachmentData:myData mimeType:@"text/plain" fileName:fileNameToSend];
// text/html/
// Fill out the email body text
NSString *emailBody = [NSString stringWithFormat:@"%@",@"Hello! This is export test."];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
// NSLog(@"here2");
switch (result)
{
case MFMailComposeResultCancelled: break;
case MFMailComposeResultSaved: break;
case MFMailComposeResultSent: break;
case MFMailComposeResultFailed: break;
default: break;
}
// self.navigationController.navigationBarHidden=NO;
// [self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}
-(iAction)btnPressedExport:(id)发送方{
NSArray*x=[[NSArray alloc]initWithArray:[DatabaseAccess getAllTransactionsForUserID:[BudgetTrackpDelegate getUserID]配置文件ID:[BudgetTrackpDelegate getProfileID]];
int i=-1,j=[x计数];
国家统计局*tmp;
NSMutableString*stringToWrite=[[NSMutableString alloc]init];
对于(;i这看起来是错误的,除非只是为了测试:
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"myExport" ofType:@"csv"];
NSData *myData = [NSData dataWithContentsOfFile:path];
您使用的路径是指向应用程序包中的文件,该文件是只读的,因此它不能是您刚才创建的CSV文件
如果你想写一个临时文件并通过电子邮件发送,你需要把它写到像你的文档目录这样的地方,即像
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/myexport.csv", docDirectory];
它是受支持的附件类型吗?是的!我见过许多应用程序使用此扩展。你能显示你用来发送的代码吗?如果你给自己发送一封电子邮件,其中包含来自mail的相同附件,它会显示吗?好的。让我编辑这个问题。