iphone - UIPasteBoard 不粘贴音频文件?

标签 iphone sms uipasteboard

我正在开发一个应用程序,其中一个模块是一个简单的列表 TableView,显示音频文件列表。当用户选择任何音频文件时,操作表会附带选项 SMS 之一。我需要通过短信发送特定的音频文件。请让我知道如何处理这个问题。

如果这是不可能的,请向我提供苹果文档,以便它作为我展示的证据。

这是我尝试粘贴音频文件的方法...

第一种方法:

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"]]];

第二种方式:

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];
}

我知道这可以通过发布到服务器并从那里检索来实现。但是,这不是要求。

任何帮助将不胜感激,如果不可能,请提供苹果文档。

最佳答案

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.

关于iphone - UIPasteBoard 不粘贴音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12971160/

相关文章:

ios - iOS7 中一致的后台获取?

iphone - IAP 创建 - 否 "Hosted Content"

ios - 如何使用 Swift 将文本复制到剪贴板/粘贴板

objective-c - 复制图标Photos.app

ios - 如何知道 UIPasteboard.general.URL 中的 url 是否有效?

iphone - 在运行时使用 NSUserDefaults 更改 PickerView 组件的数量

ios - Xcode 不允许我拖放按钮

iOS:在应用程序处于事件状态时阅读短信,就像 Drivesafe.ly 一样

android - 如何使用电话簿中的联系人发送短信而不是写电话号码?

Android 短信确认对话框