6

我正在尝试使用 UIAcitivityViewController 电子邮件共享来共享相机胶卷图像。

以下是我的代码。

 ALAssetRepresentation *rep = [asset defaultRepresentation];
    CGImageRef iref = [rep fullScreenImage];
    UIImage *largeimage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp];
    NSData *imageData = UIImageJPEGRepresentation(largeimage, 1.0);
    NSArray *activityItems;

    if (largeimage != nil) {
        activityItems = @[imageData];
    }

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];

我不知道如何设置附件图像文件名。有什么建议吗?

4

4 回答 4

5

尝试将图像保存在本地,然后发送文件 url,它肯定会显示您的图像名称。

ALAssetRepresentation *rep = [asset defaultRepresentation];
CGImageRef iref = [rep fullScreenImage];
UIImage *largeimage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp];
NSData *imageData = UIImageJPEGRepresentation(largeimage, 1.0);
// Store imageData locally
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* filePath = [documentsPath stringByAppendingPathComponent:"@abc.jpg"];
[imageData writeToFile:filePath atomically:YES];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];

UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[fileUrl]
                                          applicationActivities:nil];
[self.navigationController presentViewController:activityViewController animated:YES completion:^{}];
于 2013-04-08T08:14:59.517 回答
1

试试这个...

NSString *text = @"write text here";
UIImage *image = [UIImage imageNamed:@"your image name"];
NSArray *activityItems = [NSArray arrayWithObjects:text,image , nil];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
于 2013-01-16T12:02:51.360 回答
0

例如,您可以像这样制作自己的内容,您可以在此链接中找到它:https ://github.com/nferocious76/NFActivityModel随便玩一下,您还可以添加密件抄送、抄送收件人。

NSURL *fileURL = [NSURL URLWithString:pdfFileURL];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfFileURL];

NFActivityShareMailIAttachment *shareMailAttachment = [[NFActivityShareMailIAttachment alloc] initWithAttachmentData:pdfData attachmentDataMimeType:@"application/pdf" attachmentDataFilename:pdfFilename];

NSString *taskName = self.reportInfo[@"TaskName"] ?: @"PDF Share";
NSString *sharingUser = self.reportInfo[@"SharingUser"] ?: @"JV User";

// define ShareMail item
NSString *mailBody = @"ShareMail Body";
NFActivityShareMailItem *activityShareMailItem = [[NFActivityShareMailItem alloc] initWithShareMailSubject:taskName mailBody:mailBody isHTML:NO];
activityShareMailItem.attachments = @[shareMailAttachment];

// create ShareMail with the base view controller
NFActivityShareMail *shareMail = [[NFActivityShareMail alloc] initWithViewController:self];

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[pdfData, fileURL, activityShareMailItem] applicationActivities:@[shareMail]];
activityViewController.excludedActivityTypes = @[UIActivityTypeMail];

// present to user
[self presentViewController:activityViewController animated:YES completion:nil];
于 2017-04-11T07:11:49.577 回答
-1

在您的共享方法中尝试此代码..

// add all objects in array which you want to attach. 
    NSArray *dataToShare =[[NSArray alloc] initWithObjects:title.text,notes.text,image,nil];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
    [self presentViewController:activityVC animated:YES completion:^{

            }];
于 2013-06-19T11:53:46.207 回答