我正在尝试发送包含带有文本的图像的视图,并使用此代码转换为图像
- (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];
}
但它不起作用;任何人都可以告诉我这段代码有什么不对