我正在使用 instagram-ios-sdk
将 Instagram 集成到我的应用程序中。我可以成功 login
到 Instagram 并获得访问 token ,但是之后当我尝试使用 UIImagePickerController
中的 UIDocumentInteractionController
发布图片时,图片未发布。发送图片的代码如下:
(void)_startUpload:(UIImage *) image {
NSLog(@"Image Object = %@",NSStringFromCGSize(image.size));
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.igo"];
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
NSLog(@"file url %@",jpgPath);
NSURL *igImageHookFile = [[NSURL alloc] init];
igImageHookFile = [NSURL fileURLWithPath:jpgPath];
NSLog(@"File Url = %@",igImageHookFile);
documentInteractionController.UTI = @"com.instagram.photo";
[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self setupControllerWithURL:igImageHookFile usingDelegate:self];
[documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
(UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
NSLog(@"%@",fileURL);
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
我把图片转成了.ig
格式,分辨率为(612 *612)。但是图片仍然没有发布到 Instagram
上。我错过了什么吗?谁能帮我解决这个问题?
谢谢
最佳答案
首先,在您的代码中,您没有将 setupControllerWithURL: usingDelegate:
的返回值分配给一个对象,因此该方法实际上并没有完成任何事情,只是创建了一个新的实例UIDocumentInteractionController 并丢弃它。
其次,来自文档:
"Note that the caller of this method needs to retain the returned object."
据我所知,您没有保留文档 Controller (或在 ARC 的情况下将其分配给强引用属性)。
试试这个 - 在你的@interface 中:
@property (nonatomic, strong) UIDocumentInteractionController *documentController;
在你的@实现中:
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.documentController.delegate = self;
self.documentController.UTI = @"com.instagram.photo";
[self.documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
另外,NSURL *igImageHookFile = [[NSURL alloc] init];
行是不必要的,因为在下一行 igImageHookFile = [NSURL fileURLWithPath:jpgPath];
你'正在创建一个新实例并丢弃第一个实例。只需使用 NSURL *igImageHookFile = [NSURL fileURLWithPath:jpgPath];
关于iphone - 图片无法从 iOS 6 发布到 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14372137/