问题
In iOS 7, there is support for adding attachments in sms messages via third party applications.
I want to know:
What kind of files are supported as attachments? e.g. .png, .pdf etc.
Can I send NSData through an sms/mms message? e.g. .dat format
Would the recipient of these messages be able to open these attachments in third party applications using iOS's "Open In" feature?
回答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.
回答2:
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)
来源:https://stackoverflow.com/questions/24906712/send-attachments-using-sms-mms-in-ios-sdk