1

我正在开发从 ipod 库附加音频文件的应用程序,我使用 MPMediaPickerController 获取音频详细信息。我得到了所有的细节。我什至得到了音频的路径和 URL。我什至将音频附加到电子邮件中,并且在电子邮件的撰写视图中可见。但是当它被发送时,它是不可见的。请帮助我。

 -(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];
 */

}

附加后的图像看起来像这样在此处输入图像描述

附件后的图像看起来像这样![电子邮件已发送,但我们没有在实际邮件中收到附件

4

0 回答 0