我使用instagram-ios-sdk
将Instagram集成到我的应用程序中。我可以成功login
到Instagram并获取访问令牌,但之后当我尝试使用UIDocumentInteractionController
中的UIImagePickerController
发布图片时,图片不会发布。发送图片的代码如下:
(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
上发布。我错过了什么吗?任何人都能帮助我吗?
谢谢
答案 0 :(得分:0)
首先,在你的代码中,你没有将setupControllerWithURL: usingDelegate:
的返回值赋给一个对象,所以该方法实际上并没有完成任何事情,只是创建一个新的UIDocumentInteractionController实例并将其丢弃。 / p>
其次,来自文档:
"Note that the caller of this method needs to retain the returned object."
我不会保留文档控制器(或者在ARC的情况下将其分配给强烈引用的属性)。
试试这个 - 在@interface中:
@property (nonatomic, strong) UIDocumentInteractionController *documentController;
在@implementation中:
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];