简体   繁体   English

如何通过iMe​​ssage ios 8发送音频文件

[英]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. 以下是这样做的步骤。

  1. Check if file can be send using file UTI using + (BOOL)isSupportedAttachmentUTI:(NSString *)uti 使用+ (BOOL)isSupportedAttachmentUTI:(NSString *)uti检查文件是否可以使用文件UTI发送+ (BOOL)isSupportedAttachmentUTI:(NSString *)uti
  2. Find File UTI. 查找文件UTI。 ie path for the file 即文件的路径
  3. Attach file to 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.

相关问题 通过xcode(swift)中的iMessage应用程序发送音频文件 - Send an audio file through iMessage Application in xcode (swift) 如何通过在iMessage中点击“发送”等操作从iOS键盘扩展中检测到文本字段被清除? - How to detect from iOS keyboard extension that a textfield is cleared via actions like hitting “Send” in iMessage? 如何在没有 iMessage 的情况下发送短信 - How send SMS without iMessage 如何在iMessage App Extension上以输入字段中的文本形式发送消息? - How do I send a message on iMessage App Extension as a text in the input field? 在iOS中的iMessage中以编程方式发送图片+文本? - send picture + text in iMessage in ios programatically? 如何通过http帖子将音频文件从ios发送到服务器? - how to send audio file through http post to a server from ios? 在iOS中发送音频FILE和JSON字符串 - Send an audio FILE and JSON string in iOS 如何使用 FCM 向 iOS 发送通知? - How do I send a notification to iOS with FCM? 如何在iMessage扩展中将事件发送到Firebase Analytics - How to send events to Firebase Analytics in iMessage extension React Native Firebase 动态链接通过 iMessage 发送不正确 - React Native Firebase dynamic links send improperly via iMessage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM