0

我正在向电子邮件发送声音文件,但我只想为电子邮件更改其名称。

假设我拿了一些sound.caf,在我的文件夹中,我想留下它的名字,但是要复制它,更改它的名字,然后发送它。

我将展示我如何发送电子邮件,我需要最简单的方法来更改文件名而不影响原始文件名:

//send email log-------------------------
NSLog(@"mail");
[[CCDirector sharedDirector] pause];

picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

 NSArray *toRecipients = [NSArray arrayWithObject:@"your email"];
[picker setToRecipients:toRecipients];

NSString *sound=[NSString stringWithFormat:@"sound%d.caf",[memoryInstnace getSoundToEdit]];  //here, i need to change the name of the copy .

NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths2 objectAtIndex:0] stringByAppendingPathComponent:sound];
NSData *data = [NSData dataWithContentsOfFile:dataPath];
[picker addAttachmentData:data mimeType:@"caf" fileName:sound];//

NSString *emailBody = @"my sound  ";
[picker setMessageBody:emailBody isHTML:NO];
[picker setSubject:@"  new message "];

//display the view
[[[CCDirector sharedDirector] view] addSubview:picker.view];
//[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];
4

1 回答 1

0

只需在此处输入您喜欢的文件名:

[picker addAttachmentData:data mimeType:@"caf" fileName:myFileName];

它将被接收为myFileName而不是sound. 实际上,您只是在电子邮件中附加了一些数据;这与数据的来源无关(可能是文件、网络等);附加时,您指定在接收端将数据识别为附件的名称。

于 2012-09-13T09:08:55.423 回答