【发布时间】:2013-10-03 22:56:25
【问题描述】:
我想在 iOS7 上将图像附加到彩信。我写了以下代码:
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
NSData *imgData = [NSData dataWithContentsOfFile:@"blablabla"];
BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"image"];
if (didAttachImage)
{
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];
}
else
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Failed to attach image"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[warningAlert show];
return;
}
问题是当短信画面出现时,无法识别图片,无法发送。我看到这样的东西:
我相信这与我发送的 imgData 或 typeIdentifier 有关。
注意:我尝试了几乎所有可能的类型标识符: @"public.data", @"public.image", @"public.item", ... 等等。都没有工作。
有人可以帮帮我吗?您使用的 typeIdentifier 是什么?我正在 iPhone 5、iOS 7.0.2 上进行测试。
谢谢。
解决方案:
按照 Greg 的指示,这解决了我的问题:将文件名设置为 @"image.png",并将 typeIdentifier 设置为 kUTTypePNG。
[messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:@"image.png"];
谢谢格雷格。
【问题讨论】:
-
我得到 didAttachImage = YES 但我在显示的 SMS 屏幕中看不到任何附加图像。我正在 Iphone 6plus、iOS 8.4.1 上进行测试
标签: ios ios7 mms uti mfmessagecomposeview