title: IOS:MPMediaItems raw song converting to NSData
body: <p>I used this code It's fine,but after converted the song to data and when i'm trying to send that converted data to MFMailComposeViewController or MFMessageComposeViewController, It's coming in Document format some times but failed to get the mp3 format.When I'm playing the song,which we sent to the MFmailComposeViewcontroller or MFMessageComposeViewController , the songs which converted correctly was playing correct but some is converting to document format . How to overcome this. Please suggest me . </p>
  
  <p>SelectedAlbumUrl = [[arr_tablVArray objectAtIndex:indexPath.row] objectForKey:@"SongUrl"];</p>
  
  <p>This method calling like this.</p>
  
  <pre><code>[self mediaItemToData:[arr_tablVArray objectAtIndex:indexPath.row]];
  
  -(void)mediaItemToData : (MPMediaItem * ) curItem
  {
      NSURL *url = SelectedAlbumUrl;
      AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil];
      AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset
                                                                        presetName:AVAssetExportPresetAppleM4A];
      exporter.outputFileType =   @"com.apple.m4a-audio";
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString * myDocumentsDirectory = ([paths count] &gt; 0) ? [paths objectAtIndex:0] : nil;
  
      [[NSDate date] timeIntervalSince1970];
      NSTimeInterval seconds = [[NSDate date] timeIntervalSince1970];
      NSString *intervalSeconds = [NSString stringWithFormat:@"%0.0f",seconds];
  
      NSString * fileName = [NSString stringWithFormat:@"%@.caf",intervalSeconds];
      NSLog(@"the file name is ---&gt;%@",fileName);
  
      NSString *exportFile = [myDocumentsDirectory stringByAppendingPathComponent:fileName];
  
      exportURL = [NSURL fileURLWithPath:exportFile];
      exporter.outputURL = exportURL;
  
      // (completion handler block omitted)
      [exporter exportAsynchronouslyWithCompletionHandler:
       ^{
           int exportStatus = exporter.status;
  
           switch (exportStatus)
           {
               case AVAssetExportSessionStatusFailed:
               {
                   NSError *exportError = exporter.error;
                   NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
                   break;
               }
               case AVAssetExportSessionStatusCompleted:
               {
                   NSLog (@"AVAssetExportSessionStatusCompleted");
  
                   NSData *data = [NSData dataWithContentsOfFile: [myDocumentsDirectory
                                                                   stringByAppendingPathComponent:fileName]];
  
                   data = nil;
                   break;
               }
               case AVAssetExportSessionStatusUnknown:
               {
                   NSLog (@"AVAssetExportSessionStatusUnknown"); break;
               }
               case AVAssetExportSessionStatusExporting:
               {
                   NSLog (@"AVAssetExportSessionStatusExporting"); break;
               }
               case AVAssetExportSessionStatusCancelled:
               {
                   NSLog (@"AVAssetExportSessionStatusCancelled"); break;
               }
               case AVAssetExportSessionStatusWaiting:
               {
                   NSLog (@"AVAssetExportSessionStatusWaiting"); break;
               }
               default:
               {
                   NSLog (@"didn't get export status"); break;
               }
           }
       }];
  }
  
  After that url converting to NSData sending through email,message and airdrop like this 
  NSData *Data = [NSData dataWithContentsOfURL:exportURL];
          [composer addAttachmentData:Data mimeType:@".caf" fileName:str_songtitle];
  </code></pre>