用Instagram打开图像

时间:2012-05-05 16:46:00

标签: iphone objective-c ios xcode ipad

嗨我需要在Instagram中导入我编辑过的图像,比如PhotoStudio:

enter image description here

我使用以下代码捕获了我的图片:

    UIGraphicsBeginImageContextWithOptions(self.captureView.bounds.size, self.captureView.opaque, 0.0);
    [self.captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

然后我需要用Instagram打开这个screenShot


EDITED

我实现了这样的方法:

    UIGraphicsBeginImageContextWithOptions(self.captureView.bounds.size, self.captureView.opaque, 0.0);
    [self.captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", screenshot]];

    docFile.UTI = @"com.instagram.photo";
    [self setupDocumentControllerWithURL:igImageHookFile];

    NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
        [[UIApplication sharedApplication] openURL:instagramURL];
    }

    else {   
        NSLog(@"No Instagram Found");
    }
}

但是我收到了这个输出:

2012-05-05 21:55:36.842 InstantFrame[855:707] *** Assertion failure in -[UIDocumentInteractionController setURL:], /SourceCache/UIKit/UIKit-1914.84/UIDocumentInteractionController.m:1094
2012-05-05 21:55:36.848 InstantFrame[855:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController: invalid scheme (null).  Only the file scheme is supported.'

Instagram将被打开,但不会导入任何内容。

2 个答案:

答案 0 :(得分:1)

您要做的是打开特殊格式的网址。

以下是我通过快速谷歌搜索找到的instragram文档:

http://instagr.am/developer/iphone-hooks/

以下是介绍网址方案流程的Apple文档。 http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007891-SW1

答案 1 :(得分:0)

要在Instagram上分享图像,最小图像尺寸应为612x612。另外,它不会导入图像。