我在app上工作,我从ipod库附加了一个音频文件 我使用MPMediaPickerController获取音频细节。我得到了所有的细节。我甚至得到音频的路径和URl。我甚至在电子邮件中附加音频,这在电子邮件的撰写视图中可见。 但是当它被发送时它是不可见的。 Plz帮我一样。
-(void)displayComposerSheet {
NSMutableString *sub=[[NSMutableString alloc]init];
[sub setString:[NSString stringWithString:@"HiFive"]];
NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
NSString *str=[song valueForProperty:MPMediaItemPropertyTitle];
str=[str stringByAppendingFormat:@".mp3"];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
NSError *assetError = nil;
AVAssetReader *assetReader = [[AVAssetReader assetReaderWithAsset:songAsset
error:&assetError]retain];
if (assetError) {
NSLog (@"error: %@", assetError);
return;
}
AVAssetReaderOutput *assetReaderOutput = [[AVAssetReaderAudioMixOutput
assetReaderAudioMixOutputWithAudioTracks:songAsset.tracks
audioSettings: nil]
retain];
if (! [assetReader canAddOutput: assetReaderOutput]) {
NSLog (@"can't add reader output... die!");
return;
}
[assetReader addOutput: assetReaderOutput];
NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
NSString *exportPath = [[documentsDirectoryPath stringByAppendingPathComponent:str] retain];
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) {
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
NSString *Newpath = [[NSString alloc] initWithFormat:@"%@/%@",documentsDirectoryPath,str];
NSURL *exportURL = [NSURL fileURLWithPath:exportPath];
[[NSFileManager defaultManager] copyItemAtPath:exportPath toPath:Newpath error:nil];
NSURL *theFileUrl = [NSURL URLWithString:Newpath];
NSLog(@"theFileUrl: %@",theFileUrl);
NSLog(@"Newpath: %@",Newpath);
NSData *data=[NSData dataWithContentsOfFile:Newpath];
NSLog(@"%d",[data length]);
NSString *eMailBody=[NSString stringWithString:@"I am with you!!!"];
NSString *encodedBody =[eMailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
MFMailComposeViewController *controller =
[[MFMailComposeViewController alloc]init];
controller.mailComposeDelegate = self;
[controller addAttachmentData:data mimeType:@"audio/mp3" fileName:str];
[controller setSubject:sub];
[controller setMessageBody:[NSString stringWithFormat:@"%@ ",encodedBody] isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
/*
// Converts the sound's file path to an NSURL object
NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
NSData *data=[[NSData alloc]initWithContentsOfURL:newURL];
NSString *eMailBody=[NSString stringWithString:@"I am with you!!!"];
NSString *encodedBody =[eMailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
MFMailComposeViewController *controller =
[[MFMailComposeViewController alloc]init];
controller.mailComposeDelegate = self;
[controller addAttachmentData:data mimeType:@"audio/x-caf" fileName:@"sound"];
[controller setSubject:sub];
[controller setMessageBody:[NSString stringWithFormat:@"%@ ",encodedBody] isHTML:NO];
//[controller setToRecipients:[NSArray arrayWithObject:@"abhishek@iarianatech.com"]];
[self presentModalViewController:controller animated:YES];
[controller release];
*/
}
atachment后的图像看起来像
atachment之后的图像看起来像这样![发送电子邮件但我们没有在实际邮件中获得附件