6

附加的图像只是“Attachment-1”,没有扩展名。我如何指定一个?

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

2 回答 2

14

根据此答案,您应该可以使用此解决方法来指定文件名

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

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

于 2013-04-05T05:34:17.847 回答
0

归功于 timeuser 的建议,将 UIImage 转换为 NSData。

NSData * data = UIImageJPEGRepresentation(original,1.0);
UIActivityViewController * activity =[[UIActivityViewController alloc] initWithActivityItems:@[@"Your Text", data] applicationActivities:nil];
[self presentViewController:activity animated:true completion:^{ }];
于 2016-07-25T16:28:33.600 回答