I want to share image on instagram from my app its working quite well but the problem comes when i share the same image second time the image become zoom in and some part of the image become messed up here is my code for sharing.
-(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;
}
Updates always cause problems. The following will work for you (given you declare documentInteractionController in the interface):
NSURL *instagramURL = [NSURL URLWithString:@"instagram://yourApp"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]){
NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.igo"];
[UIImageJPEGRepresentation(yourImage, 1.0) writeToFile:jpgPath atomically:YES];
NSURL *fileURL = [NSURL fileURLWithPath:jpgPath];
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
documentInteractionController.UTI = @"com.instagram.exclusivegram";
documentInteractionController.delegate = self;
documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Your App" forKey:@"InstagramCaption"];
[documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.