[英]How do I send audio file send via iMessage ios 8
As we know with the launch of ios 8 the apple allow custom Keyboard extension.In keyboard extension we can send images,gif etc in SMS by using Copy image to clipboard.code 正如我们所知,随着ios 8的推出,苹果允许自定义键盘扩展。在键盘扩展中我们可以通过使用复制图像到剪贴板来发送短信中的图像,gif等。
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data= UIImagePNGRepresentation([UIImage imageNamed:@"so_close_disappointed_meme.png"]);
[pasteboard setData:data forPasteboardType:@"public.png"];
Now i am trying to send audio file in iMessage like this feature reference .don't know apple will allow us to send audio in iMessage?.so for i tried above approach but it did not show any paste option for audio in SMS window. 现在我正试图在iMessage中发送音频文件,就像这个功能参考一样。不知道苹果会允许我们在iMessage中发送音频吗?.so我试过上面的方法,但它没有在SMS窗口中显示音频的任何粘贴选项。
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *path = [[NSBundle mainBundle] pathForResource:@"tune"ofType:@"mp3"];
NSURL *url = [[NSURL alloc] initWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
[pasteboard setData:data forPasteboardType:@"public.mp3"];
Any one can suggest me how do we send audio file by using custom keyboard extension.is it possible? 任何人都可以建议我如何通过使用自定义键盘扩展发送音频文件。它可能吗?
I believe you could directly attach the file to MFMessageComposeViewController
. 我相信你可以直接将文件附加到
MFMessageComposeViewController
。 Here is the documentation link of how it could be done. 以下是如何完成的文档链接 。
Following would be the steps to do so. 以下是这样做的步骤。
+ (BOOL)isSupportedAttachmentUTI:(NSString *)uti
+ (BOOL)isSupportedAttachmentUTI:(NSString *)uti
检查文件是否可以使用文件UTI发送+ (BOOL)isSupportedAttachmentUTI:(NSString *)uti
MFMessageComposeViewController
using - (BOOL)addAttachmentData:(NSData *)attachmentData typeIdentifier:(NSString *)uti filename:(NSString *)filename
- (BOOL)addAttachmentData:(NSData *)attachmentData typeIdentifier:(NSString *)uti filename:(NSString *)filename
将附件文件附加到MFMessageComposeViewController
- (BOOL)addAttachmentData:(NSData *)attachmentData typeIdentifier:(NSString *)uti filename:(NSString *)filename
As the description for the method says 正如该方法的描述所说
This method is especially useful when the attachment you want to add to a message does not have a file system representation.
当您要添加到邮件的附件没有文件系统表示时,此方法特别有用。 This can be the case, for example, for programmatically composed audiovisual content.
例如,对于以编程方式组成的视听内容,情况就是如此。
Note : You will have to convert audio file to NSData 注意:您必须将音频文件转换为NSData
The MFMessageComposeViewController isn't the solution in this scenario. MFMessageComposeViewController不是此方案中的解决方案。 A custom keyboard extension shouldn't present a new view controller, rather just paste the audio file to the pasteboard.
自定义键盘扩展不应提供新的视图控制器,而只是将音频文件粘贴到粘贴板。 Heres some swift code that worked for me
下面是一些适合我的快速代码
let path = NSBundle.mainBundle().pathForResource("audio", ofType:"wav")
let fileURL = NSURL(fileURLWithPath: path!)
let data = NSData(contentsOfURL: fileURL)
let wavUTI = "com.microsoft.waveform-audio"
UIPasteboard.generalPasteboard().setData(data!, forPasteboardType: wavUTI)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.