1

我正在努力将 Share to Instagram 集成到我的 iPhone 应用程序中,但我无法让编辑后的图像在 Instagram 中打开。

这是我正在尝试的代码:

    mainToolBar.hidden = YES;
    colorToolBar.hidden = YES;
    [self.view setNeedsDisplay];
    UIGraphicsBeginImageContext(CGSizeMake(320, 416));
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * imageA = [UIImage imageWithData:UIImageJPEGRepresentation(UIGraphicsGetImageFromCurrentImageContext(), 1.0)];
    UIGraphicsEndImageContext();
    mainToolBar.hidden = NO;
    colorToolBar.hidden = NO;

    NSString * documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString * savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.ig"];

    NSData * imageData = UIImagePNGRepresentation(imageA);

    [imageData writeToFile:savedImagePath atomically:YES];

    NSURL * imageUrl = [NSURL fileURLWithPath:savedImagePath];

    UIDocumentInteractionController * docController = [[UIDocumentInteractionController alloc] init];
    docController.delegate = self;
    [docController retain];

    docController.UTI = @"com.instagram.photo";

    [docController setURL:imageUrl];

    [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

如果我将 imageData 设置为等于 UIImagePNGRepresentation(self.image) 图像确实会显示,但只是原始图像,而不是编辑后的图像(绘图/着色应用程序)。

谁能帮我看看我错过了什么?

太感谢了!

4

0 回答 0