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 に答える
-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 に答える