如何通过ios 7+中的mms以编程方式发送图像?

时间:2014-12-14 13:46:31

标签: ios ios7 ios8

如何以编程方式通过ios 7+中的mms发送图像? 我在本地保存了图像名称,我需要发送mms。 ios支持这个吗?

1 个答案:

答案 0 :(得分:2)

你可以通过两种方式来解决这个问题, 1 - 使用MFMessageComposeViewController 2 - 通过彩信

在第一种方式中,您可以通过iMe​​ssage发送图像 在第二种方式,您可以通过职业网络发送彩信

对于第一个过程,代码是

-(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复制图像,然后将其粘贴到MMS屏幕

代码是

-(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];

}

如果您觉得有用,请接受答案