Прикрепите аудиофайл библиотеки ipod к электронной почте в приложении iphone - PullRequest
1 голос
/ 26 марта 2012

Я работаю над приложением, к которому прикрепляю аудиофайл из библиотеки 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];
 */

}

изображение после прикрепления выглядит следующим образом enter image description here

изображение после прикрепления выглядит следующим образом! [Электронная почта отправлена, но мы не получаем вложение в фактической почте

...