UIActivityViewController通过电子邮件共享图像没有扩展名 [英] UIActivityViewController sharing image via email has no extension

查看:99
本文介绍了UIActivityViewController通过电子邮件共享图像没有扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附加的图片只是附件-1,没有扩展名。如何指定一个?

The image attached is just "Attachment-1", no extension. How do I specify one ?

    NSData *compressedImage = UIImageJPEGRepresentation(self.resultImage, 0.8 );

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ @"Check this out!", compressedImage ] applicationActivities:nil];

    [self.navigationController presentViewController:activityViewController animated:YES completion:nil];


推荐答案

根据此答案您应该能够使用此解决方法指定文件名。

According to this answer you should be able to use this workaround to specify a filename

NSData *compressedImage = UIImageJPEGRepresentation(self.resultImage, 0.8 );
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *imagePath = [docsPath stringByAppendingPathComponent:@"image.jpg"];
NSURL *imageUrl     = [NSURL fileURLWithPath:imagePath];

[compressedImage writeToURL:imageUrl atomically:YES]; // save the file
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ @"Check this out!", imageUrl ] applicationActivities:nil];

这种方法的明显缺点是您必须将映像保存在磁盘上。

The obvious drawback of this approach is that you will have to save the image on disk.

这篇关于UIActivityViewController通过电子邮件共享图像没有扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆