Send attachments using sms/mms in iOS SDK

天涯浪子 提交于 2019-12-11 11:36:01

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!