How do I send audio file send via iMessage ios 8
Asked Answered
S

2

5

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

 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.

 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?

Swap answered 2/2, 2015 at 6:49 Comment(1)
I never knew that this was possible on iOS devices but this sounds really cool!Mercurialize
B
9

I believe you could directly attach the file to 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
  2. Find File UTI. i.e. path for the file
  3. Attach file to MFMessageComposeViewController using - (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

Bernardina answered 5/2, 2015 at 6:28 Comment(2)
I have tried above approach for sending audio file directly via SMS but still did not achieved the desired result but it help me a a lot and i hope after bit research i will get the desired result.Swap
Just make sure you have iMessage turned on and associated with a AppleID. Even I might try to create a example if time allows me to :). Good LuckBernardina
P
0

The MFMessageComposeViewController isn't the solution in this scenario. 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)
Prine answered 7/7, 2015 at 1:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.