我想从我的应用程序在 Instagram 上共享图像,它工作得很好,但是当我第二次共享同一张图像时,图像变得放大并且图像的某些部分变得混乱时,问题就出现了,这是我的共享代码。
-(void)shareImageToInstagram
{
myview.hidden = NO;
shareImage.image = [self ChangeViewToImage:myview];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
CGRect cropRect=CGRectMake(0,0,306,306);
NSString *savePath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
CGImageRef imageRef = CGImageCreateWithImageInRect([shareImage.image CGImage], cropRect);
UIImage *img = [[UIImage alloc] initWithCGImage:imageRef];
CGImageRelease(imageRef);
[UIImageJPEGRepresentation(img, 1.0) writeToFile:savePath atomically:YES];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",savePath]];
self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic.annotation = [NSDictionary dictionaryWithObject:kCheckOut forKey:@"InstagramCaption"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
[self.dic presentOpenInMenuFromRect: CGRectZero inView: self.view animated: YES ];
myview.hidden = YES;
}
else
{
ALERT_VIEW(@"Instagram not installed in this device!\nTo share image please install instagram.");
myview.hidden = YES;
}
}
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
myview.hidden = YES;
return interactionController;
}