Note that there are some explanatory texts on larger screens.

plurals
  1. POAttach ipod library audio file to Email in iphone app
    text
    copied!<p>I am working on app where i am attaching a Audio file from ipod library i Get the audio detail using MPMediaPickerController. I get all the details. I even get the path and URl for the Audio. I even attach the audio in email and which is visible in compose view of the Email. But when it is sent it is not visible. Plz help me with the same.</p> <pre><code> -(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:&amp;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]; */ </code></pre> <p>}</p> <p>the image after atachment looks like this <img src="https://i.stack.imgur.com/tEOV5.png" alt="enter image description here"></p> <p>the image after atachment looks like this ![email gets sent but we dont get the attachment in actual mail</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload