【问题标题】:How to send image via mms in ios 7+ programmatically? [closed]如何以编程方式通过 ios 7+ 中的 mms 发送图像? [关闭]
【发布时间】:2014-12-14 13:46:30
【问题描述】:

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

【问题讨论】:

    标签: ios ios7 ios8


    【解决方案1】:

    你可以通过两种方式来解决这个问题, 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];
    
    }
    

    如果你觉得有用,请采纳答案

    【讨论】:

    • @Janmejaya 感谢您的回复,秒工作,只是先问一下,什么是选择器?再次感谢。
    • @PaolaJ。选择器是 MFMessageController 类的对象。我正在为你编辑答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 2010-11-06
    • 1970-01-01
    相关资源
    最近更新 更多