简体   繁体   中英

Image not post on instagram from ios 6

I am integrating Instagram into my application using the instagram-ios-sdk . I can successfully login to Instagram and obtain an access token, but after that when I am try to post a picture using UIDocumentInteractionController from UIImagePickerController , the image is not posting. The code to send a picture is given below:

(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;
}

I converted the image to .ig format, with a resolution of (612 *612). But still the image is not posting on Instagram . Am I missing something? Can any one help me with this?

Thanks

First off, in your code, you're not assigning the return value of setupControllerWithURL: usingDelegate: to an object, so that method isn't actually accomplishing anything, just creating a new instance of UIDocumentInteractionController and discarding it.

Secondly, from the documentation:

"Note that the caller of this method needs to retain the returned object."

You're not retaining the document controller (or assigning it to a strongly referenced property in the case of ARC) from what I can tell.

Try this - In your @interface:

@property (nonatomic, strong) UIDocumentInteractionController *documentController;

In your @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];

Also, the line NSURL *igImageHookFile = [[NSURL alloc] init]; is unnecessary because in the next line igImageHookFile = [NSURL fileURLWithPath:jpgPath]; you're creating a new instance and discarding the first one. Just use NSURL *igImageHookFile = [NSURL fileURLWithPath:jpgPath];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM