在发送电子邮件之前更改声音文件名的副本

时间:2012-09-13 08:46:31

标签: objective-c

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

让我说我需要一些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];

1 个答案:

答案 0 :(得分:0)

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

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

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