从我的iOS应用程序分享照片到Instagram [英] Share photo to Instagram from my iOS App

查看:633
本文介绍了从我的iOS应用程序分享照片到Instagram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索从我正在开发的iOS应用中将照片发布到Instagram的方法。但是看到一些链接,似乎他们不支持使用他们的API进行写访问。那么,

I have been searching a way to post photo to Instagram from a iOS app I am developing. But seeing some links , it seems to be they don't support write access using their API. So,


  1. 是否可以通过某些API或Instagram API从iOS分享照片到Instagram?

  2. 如果可能,有人可以建议我做一个教程或文档吗?

他们的api说这个......

Their api says this...

此时,无法通过API上传。我们有意识地选择不添加此内容,原因如下:

"At this time, uploading via the API is not possible. We made a conscious choice not to add this for the following reasons:

Instagram是关于你在旅途中的生活 - 我们希望鼓励应用程序内的照片。但是,将来我们可能会根据具体情况给白名单访问个人应用程序。
我们想要打击垃圾邮件和低质量的照片。一旦我们允许从其他来源上传,就很难控制Instagram生态系统的内容。所有这些,我们正在努力确保用户获得一致和高质量的体验。我们的平台。

Instagram is about your life on the go – we hope to encourage photos from within the app. However, in the future we may give whitelist access to individual apps on a case by case basis. We want to fight spam & low quality photos. Once we allow uploading from other sources, it's harder to control what comes into the Instagram ecosystem. All this being said, we're working on ways to ensure users have a consistent and high-quality experience on our platform."

这就是为什么我在寻找更好的建议。

That's why I am looking for any better suggestion.

谢谢提前帮助。

推荐答案

请在设备中尝试此代码....共享在模拟器中不起作用

Please try this code in device.... sharing doesn't work in Simulator

它会将图像从应用程序保存到文档目录,它将共享相同的图像到Instagram。

It will save image from app to document directory and it will share the same image to instagram.

为了分享我会只接受.igo格式

For sharing i will take .igo format only

-(void)shareInInstagram
{
  NSData *imageData = UIImagePNGRepresentation(imge); //convert image into .png format.

    NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it

    NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //add our image to the path

    [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)

    NSLog(@"image saved");


    CGRect rect = CGRectMake(0 ,0 , 0, 0);
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIGraphicsEndImageContext();
    NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"];
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave];
    NSLog(@"jpg path %@",jpgPath);
    NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath]; //[[NSString alloc] initWithFormat:@"file://%@", jpgPath] ];
    NSLog(@"with File path %@",newJpgPath);
    NSURL *igImageHookFile = [[NSURL alloc] initFileURLWithPath:newJpgPath];
    NSLog(@"url Path %@",igImageHookFile);

    self.dic.UTI = @"com.instagram.exclusivegram";
    self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
    self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    [self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];


}



- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
    NSLog(@"file url %@",fileURL);
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}

这篇关于从我的iOS应用程序分享照片到Instagram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆