美好的一天!我只想问一下如何将编程截图图像附加到iMessage?
这是我使用的截图代码
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshotimage, nil, nil, nil);
现在我有了这段代码,以编程方式为任何指定的号码或电子邮件创建iMessage,
MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc]init];
[textComposer setMessageComposeDelegate:self];
NSString *messagebody = [NSString stringWithFormat:@"Here's my message"];
if ([MFMessageComposeViewController canSendText]) {
[textComposer setRecipients: [NSArray arrayWithObjects:@"sample@email.com", nil]];
[textComposer setBody:messagebody];
[self presentViewController:textComposer animated:YES completion:NULL];
} else {
NSLog(@"Can't Open Text");
}
现在,我试过的是这个,
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//UIImageWriteToSavedPhotosAlbum(screenshotimage, nil, nil, nil);
MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc]init];
[textComposer setMessageComposeDelegate:self];
NSString *attachmentmessage = [NSString stringWithFormat:@"Here's my Screenshot %@",screenshotimage];
if ([MFMessageComposeViewController canSendText]) {
[textComposer setRecipients: [NSArray arrayWithObjects:@"sample@email.com", nil]];
[textComposer setBody:attachmentmessage];
[self presentViewController:textComposer animated:YES completion:NULL];
} else {
NSLog(@"Can't Open Text");
}
是的,它会自动创建预设消息,但Image i&ve; screenshot屏幕截图不在附件中?这是我得到的示例预设消息
"这是我的截图UIImage:0x16d9a180>"
答案 0 :(得分:0)
你需要这个
NSString *attachmentmessage = @"Here's my Screenshot"];
if ([MFMessageComposeViewController canSendText]) {
[textComposer setRecipients: [NSArray arrayWithObjects:@"sample@email.com", nil]];
[textComposer setBody:attachmentmessage];
[textComposer addAttachmentData:UIImageJPEGRepresentation(screenshotimage,1.0) typeIdentifier:@"public.data" filename:@"image.png"];
[self presentViewController:textComposer animated:YES completion:NULL];