如何通过iPhone应用程序附加图片消息?

我想发送带有图像数据的消息。 所以我使用了MFMessageComposeViewController 。 但是那个控制器只提供SMS服务。 所以我用UIPasteBoard附上了一个图像数据。 但是它也行不通。 input消息时没有创build“粘贴”button。 在UIPasteBoard附加图片显然是成功的。 我认为使用MFMessageComposeViewController不能解决我的问题。 我怎样才能实现我的目标?

对于当前的MessageUI API,这是不可能的:MSMessageComposeViewController不接受像MFMailComposeViewController那样的附件。

目前唯一的方法是使用一个外部服务,例如允许你通过REST调用发送mms。

GSMA完全为此定义了一个REST规范: http : //www.gsmworld.com/oneapi/reference_documentation-version_1.html (本页有多个pdf)

尝试find一个实现这个规范的本地服务提供者,你很好。

只需将直接维基链接添加到OneAPI MMS规范: http : //gsma.securespsite.com/access/Access%20API%20Wiki/MMS%20RESTful%20API.aspx和链接到PHP / Java沙箱https:/ / github.com/OneAPI/GSMA-OneAPI MMS可以在本地进行testing。 干杯。

这是正确的工作代码,它在我的设备上完美工作。

 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.persistent = NO; NSMutableDictionary *text = [NSMutableDictionary dictionaryWithCapacity:1]; [text setValue:label.text forKey:(NSString *)kUTTypeUTF8PlainText]; NSMutableDictionary *image = [NSMutableDictionary dictionaryWithCapacity:1]; [image setValue:imageView.image forKey:(NSString *)kUTTypePNG]; pasteboard.items = [NSArray arrayWithObjects:image,text, nil]; NSString *phoneToCall = @"sms:"; NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded]; [[UIApplication sharedApplication] openURL:url]; 

我有同样的问题,我张贴在这里。 MFMessageComposeViewController有一个错误,如果你只是使用下面的代码,它会启动一个消息,你可以插入图像到

  NSString *phoneToCall = @"sms: 123-456-7890"; NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded]; [[UIApplication sharedApplication] openURL:url]; 

此方法已经过testing和validation。 我在我的代码中使用它。

 if (![MFMessageComposeViewController canSendText]) { UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device not support SMS \nOr you hadn't login your iMessage" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [alertV show]; return; } MFMessageComposeViewController *mVC = [[MFMessageComposeViewController alloc] init]; mVC.body = @"jjjj"; mVC.recipients = @[@"00XXXXXXXXXX"]; mVC.messageComposeDelegate = self; if ([MFMessageComposeViewController canSendAttachments]) { NSLog(@"ok"); } [mVC addAttachmentData: UIImageJPEGRepresentation([UIImage imageNamed:@"test.jpg"], 1.0) typeIdentifier:@"public.data" filename:@"image.jpeg"]; [self presentViewController:mVC animated:YES completion:nil]; 

您可以使用任何jpeg jpg和png格式。

迅速的方式。 适用于iOS11

 func shareViaMessage() { if !MFMessageComposeViewController.canSendText() { showAlert("Text services are not available") return } let textComposer = MFMessageComposeViewController() textComposer.messageComposeDelegate = self textComposer.body = "Try my #app" if MFMessageComposeViewController.canSendSubject() { textComposer.subject = "AppName" } if MFMessageComposeViewController.canSendAttachments() { let imageData = UIImageJPEGRepresentation(imageView.image!, 1.0) textComposer.addAttachmentData(imageData!, typeIdentifier: "image/jpg", filename: "photo.jpg") } present(textComposer, animated: true) } 

为什么不通过共享API分享图像和文本(select消息,如果你想排除Facebook,微博等..)