2

In iOS 7, there is support for adding attachments in sms messages via third party applications.

I want to know:

  1. What kind of files are supported as attachments? e.g. .png, .pdf etc.

  2. Can I send NSData through an sms/mms message? e.g. .dat format

  3. Would the recipient of these messages be able to open these attachments in third party applications using iOS's "Open In" feature?

iAmd
  • 812
  • 1
  • 12
  • 22
  • have a look this:- http://stackoverflow.com/questions/3577565/how-to-attach-image-with-message-via-iphone-application – Rushabh Jul 23 '14 at 09:43
  • Thanks @Rushabh. [This](http://stackoverflow.com/questions/14434330/how-to-use-mms-for-audio-in-iphone) is more closer to what i need. But I also want to know if I can send NSData as well. Moreover, would the recipient be able to open that attachment in a third party application using Open-In – iAmd Jul 23 '14 at 09:55

2 Answers2

1

The MFMessageComposeViewController wants the attachment to have the correct extension for the type of image you're uploading. I verified by testing with a PNG file, and the following variations of adding the attachment data:

[messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"image"];
[messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"image.abc"];
[messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"image.png"];

Only the last option worked. I didn't need to change the typeIdentifier, although it probably would make sense to choose a UTI that matches the type of data.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80
Samkit Shah
  • 721
  • 1
  • 7
  • 18
0

According to Apple MFMessageComposeViewController docs, you can do that by creating a MFMessageComposeViewController object, and add the attachment through the following functions:

func addAttachmentURL(URL, withAlternateFilename: String?)

Attaches a specified file to the message.

func addAttachmentData(Data, typeIdentifier: String, filename: String)

Attaches arbitrary content to the message.

(BTW you should check the canSendAttachments before you try to use those functions)

Joe Razon
  • 154
  • 1
  • 3
  • 13