【问题标题】:Sharing photo's to Instagram for iphone app将照片分享到 Instagram for iphone app
【发布时间】:2014-08-09 01:21:21
【问题描述】:

我正在使用以下代码示例将 Instagram 照片分享功能添加到我的 iPhone 应用中:

http://sourceforge.net/projects/nimitparekh/files/Open%20instagram/OpenInstagramController.zip/download

我的代码示例和我的应用程序也有同样的问题。 “打开方式”菜单与 Instagram、iPhoto 等一起出现,但推送时没有打开任何应用程序。你们中的一个天才可以看看代码示例并告诉我我错过了什么吗?谢谢!

这是.h代码:

@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate>{
    IBOutlet UIImageView *imageView;
}
@property(nonatomic,retain)UIDocumentInteractionController *docFile;
@property (nonatomic, retain) UIDocumentInteractionController *dic;
-(IBAction)saveToInstagram:(id)sender;

在 .m 代码中:

@synthesize docFile = _docFile;

-(IBAction)saveToInstagram:(id)sender {
        CGRect rect = CGRectMake(0 ,0 , 0, 0);

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIGraphicsEndImageContext();
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.ig"];

    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

    self.docFile.UTI = @"com.instagram.photo";
    self.docFile = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
    self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
           [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
    }
    else {   
        NSLog(@"No Instagram Found");
    }

}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}

谢谢。

【问题讨论】:

  • 我将项目中的代码添加到原始帖子中。谢谢。

标签: ios objective-c instagram


【解决方案1】:

我不确定您是如何构建文件 NSURL 实例的,但是从您的代码中可以清楚地看出一件事是您实际上并没有保存渲染的图像。 在调用 UIGraphicsEndImageContext() 之前,您需要执行类似

的操作
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();

然后是类似的东西

    NSData * imageData = UIImageJPEGRepresentation(image, 0.75);
    [imageData writeToURL: igImageHookFile atomically:YES];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2016-01-01
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多