【发布时间】:2014-12-14 13:46:30
【问题描述】:
如何通过 ios 7+ 中的 mms 以编程方式发送图像? 我在本地保存了图像名称,我需要通过 mms 发送。 ios 支持吗?
【问题讨论】:
如何通过 ios 7+ 中的 mms 以编程方式发送图像? 我在本地保存了图像名称,我需要通过 mms 发送。 ios 支持吗?
【问题讨论】:
你可以通过两种方式来解决这个问题, 1 - 通过使用 MFMessageComposeViewController 2 - 通过彩信
在第一种方式中,您可以通过 iMessage 发送图像 第二种方式,您可以通过职业网络发送彩信
对于第一个过程,代码是
-(void)sendSMSto:(NSString *)number withImage:(UIImage *)sentImage{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]) {
NSMutableString *messageBody = [[NSMutableString alloc] initWithString:@""];
picker.messageComposeDelegate = self;
picker.recipients = number?[NSArray arrayWithObject:number]:nil;// your recipient number or self for testing
[picker setBody:messageBody];
if ([picker respondsToSelector:@selector(addAttachmentData:typeIdentifier:filename:)]) {
NSData *imageData = UIImagePNGRepresentation(sentImage);
[picker addAttachmentData:imageData typeIdentifier:(@"public.image") filename:@"emoji.png"];
}
picker.body = messageBody;
ELogs(@"Picker -- %@",picker.body);
[self presentViewController:picker animated:YES completion:^{
ELogs(@"SMS fired");
}];
}
}
对于第二种方法 使用 UIPasteboard 复制图像,然后将其粘贴到彩信屏幕中
代码是
-(void)sendSMSto:(NSString *)number withImage:(UIImage *)sentImage{
if (sentImage) {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
pasteboard.image = sentImage;
}
//For sms through network career
NSString *phoneToCall = @"sms:";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
}
如果你觉得有用,请采纳答案
【讨论】: