ios - 为什么从 iOS 分享到 Instagram 时图像会变大?

标签 ios objective-c instagram

我想从我的应用程序在 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;
    }

最佳答案

更新总是会引起问题。以下内容将适合您(假设您在界面中声明 uidocumentInteractionController):

 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];

关于ios - 为什么从 iOS 分享到 Instagram 时图像会变大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18052581/

相关文章:

php - 如何使用 API 显示 Instagram 个人资料图片

ios - 用于发布视频的 Instagram iOS API

ios - 如何检测 UITableView 何时滚动到最底部/顶部?

ios - 按照 Apple 文档实现运动障碍 API 时发生错误

ios - AVPlayer 使用平移手势快进/后退

ios - NSURLSessionTaskDelegate 方法 URLSession :task:didCompleteWithError: never called

ios - 为什么每次都会返回相同的时间戳,除非我重新构建并运行应用程序?

iOS 线程并在主线程上更改 UI

iphone - Core Data : In what condition, 线程无法获取NSPersistentStoreCoordinator的锁?

javascript - 如何将 PHP Instagram 签名与 AJAX 结合使用?