Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPasteBoard doesn't paste audio files?

I am developing an app in which one of the module is, A simple listing TableView which shows the list of audio file. When user selects any audio file an action sheet comes with one of the option SMS. I Need to send the particular audio file through SMS. Please let me know how to go with this.

And if this is not possible, please provide me apple documentation so that it acts as a proof for me to show.

This is what i have tried for pasting the audio file...

First Way:

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *path = [[NSBundle mainBundle] pathForResource:@"audiofilename" ofType:@"caf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[pasteboard setData:myData forPasteboardType:@"audiofile"];
NSString  *copyPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/audiofile.caf"];
NSURL *sndURL = [NSURL fileURLWithPath:copyPath];
[pasteboard setString:[NSString stringWithFormat:@"%@",sndURL]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms:12345678"]]];

Second Way:

Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

if([messageClass canSendText])
{
    messagepicker = [[MFMessageComposeViewController alloc] init];
    messagepicker.messageComposeDelegate = self;
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"290912044119" ofType:@"caf"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [pasteboard setData:myData forPasteboardType:@"audiofile"];
    NSString  *copyPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/audiofile.caf"];
    NSURL *sndURL = [NSURL fileURLWithPath:copyPath];
    [messagepicker setBody:[NSString stringWithFormat:@"%@",sndURL]];
    [self presentModalViewController:messagepicker animated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

I know that this is possible through posting onto server and retrieving from there. But, this isn't the requirement.

Any help would be appreciated and if it's not possible then please provide with apple documents.

like image 481
Manu Avatar asked Oct 19 '12 09:10

Manu


1 Answers

It is not possible to send an audio file from message with current sdk....You can reach this requirement by upload that sound file to server and then send that url from message.

like image 70
Bajaj Avatar answered Oct 13 '22 02:10

Bajaj