iPhone:在 Instagram 上上传图片
Posted
技术标签:
【中文标题】iPhone:在 Instagram 上上传图片【英文标题】:iPhone:Upload image on Instagram 【发布时间】:2013-05-14 07:58:19 【问题描述】:我已经编写了在instagram上上传图片的代码,如下:
CGRect rect = CGRectMake(20 ,20 , 200, 200);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *jpgPath = [documentsDirectory stringByAppendingPathComponent:@"after2sm.ig"];
NSString *fileURL = [NSString stringWithFormat:@"file://%@",jpgPath];
NSURL *igImageHookFile = [NSURL fileURLWithPath:fileURL];
self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[NSDictionary dictionaryWithObject:@"My Caption" forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect:rect inView:self.view animated:YES];
但是它会打开一个带有“instagram”选项的操作表,但是当我点击它时什么都没有发生..你能帮我吗
【问题讨论】:
我要上传图片到instagram 【参考方案1】:试试这个, 在此代码中,将您的图像设置在 imgUpload 对象中
- (IBAction)InstagramButtonClick
CGRect rect = CGRectMake(0.0, 0.0, 612, 612);
UIGraphicsBeginImageContext(rect.size);
[imgUpload drawInRect:rect];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
[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=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.dic.annotation = [NSDictionary dictionaryWithObject:@"your message" forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect: CGRectZero inView: self.view animated: YES ];
//添加委托UIDocumentInteractionControllerDelegate
,下面是委托方法
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
【讨论】:
感谢您的回复。但我用你的代码得到了同样的结果。 图片尺寸要大于620*620 并检查 intstagram 应用程序应安装在设备中。这是必要的 我的图片尺寸为 650 *650 并且设备中安装了 instagram 应用 如何生成test.igo文件?以上是关于iPhone:在 Instagram 上上传图片的主要内容,如果未能解决你的问题,请参考以下文章
来自 Android 的 Instagram 在特定用户上打开并为上传的图像添加标题
使用 Selenium 和 python 为 Instagram 提供上传文件路径