2012-09-13 59 views
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]; 

回答

0

只要把文件名,你喜歡這裏:

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

,它將作爲myFileName而不是sound收到。事實上,你只是將一些數據附加到你的電子郵件中;這與數據的來源無關(可能是文件,網絡等);在附加時,指定在接收端將數據識別爲附件的名稱。

+0

哇!我很愚蠢。非常感謝 ! – user1280535

相關問題