UIPasteBoard doesn't paste audio files?

北慕城南 提交于 2019-12-04 23:09:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12971160/uipasteboard-doesnt-paste-audio-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!