如何通过iMe​​ssage以编程方式发送图像

时间:2014-08-09 18:29:34

标签: ios xcode5 mms uti mfmessagecomposeview

我正在尝试发送包含带有文本的图像的视图,并使用此代码转换为图像

- (UIImage *)imageWithView3:(UIView *)view
{
    CGSize imageSize = viewAll.bounds.size;

    UIGraphicsBeginImageContextWithOptions(imageSize, viewAll.opaque, 0.0);

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}

然后我尝试使用此代码

通过iMe​​ssage发送图像视图
if ([MFMessageComposeViewController canSendText] && [MFMessageComposeViewController canSendAttachments] && [MFMessageComposeViewController isSupportedAttachmentUTI:(NSString *)kUTTypePNG]) {

    MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
    vc.messageComposeDelegate = self;
    UIImage *myImage = [self imageWithView3:self.viewAll];
    BOOL attached = [vc addAttachmentData:UIImagePNGRepresentation(myImage) typeIdentifier:(NSString*)kUTTypePNG filename:@"image.png"];

    if (attached) {

        NSLog(@"Attached (:");
    }
    else {

        NSLog(@"Not attached ):");
    }

    [self presentViewController:vc animated:YES completion:nil];
}

但它不起作用;任何人都可以告诉我这段代码有什么不对

0 个答案:

没有答案