Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for UIActivityViewController to attach AAC?

I tried this with no luck:

        NSData *imageData = UIImageJPEGRepresentation([sight.photo valueForKey:@"image"], 0.8);

        NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

        NSString *filePath = [docsPath stringByAppendingPathComponent:@"sound.m4a"];
        NSURL *fileUrl     = [NSURL fileURLWithPath:filePath];
        NSData *aacData = [sight.sound valueForKey:@"soundrecord"];
        [aacData writeToURL:fileUrl atomically:YES];
        //    NSString *text = self.textField.text;
        NSArray *items = @[imageData, aacData];
like image 998
Shmidt Avatar asked Oct 07 '22 04:10

Shmidt


1 Answers

Yes, but you need to pass the audio file URL to the activity sheet rather than the NSData.

NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES)objectAtIndex:0];
NSString *filePath = [docPath stringByAppendingPathComponent:@"sound.aac"];

NSURL *fileUrl     = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSArray *activityItems = @[fileUrl];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

If you find that the attachment doesn't appear when launching the email composer from the activity sheet, make sure your file path and URL are correct and that the file exists (including the extension on the device/simulator drive).

To open a file on the simulator, go to folder (~/Library/Application Support/iPhone Simulator/...

To check the file name on device, go to XCode Organizer Window and select the Applications tab within the debugging device connected. You should see the file structure on the main panel.

like image 135
Juan Fran Jimenez Avatar answered Oct 10 '22 03:10

Juan Fran Jimenez