2

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

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

然后我尝试使用此代码通过 iMessage 发送图像视图

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

但它不起作用;谁能告诉我这段代码有什么问题

4

0 回答 0