coryalder / DMActivityInstagram

Instagram sharing, iOS 6 style.
MIT License
229 stars 66 forks source link

Button does nothing for square images #2

Closed richardpenner closed 11 years ago

richardpenner commented 12 years ago

First of all I was really happy to find this project, thanks for sharing it.

I'm trying to implement it, but when I tap the instragram button, nothing happens. I did a bit of debugging and found that in DMActivityInstragram.m, the last (uncommented) line in performActivity seems to be the problem.

There is a compiler warning on this line, too. But basically "self.presentInView" is nil for me, so that line essentially does nothing:

if (![self.documentController presentOpenInMenuFromBarButtonItem:self.presentInView animated:YES]) NSLog(@"couldn't present document interaction controller");

It doesn't return NO, but self.presentInView is nil. It looks like the only place that property is assigned is if an image needed to be resized. In my app I am working with images that are typically square already. So perhaps the bug is that if resizing isn't needed, it doesn't work?

Note that presentInView is declared as UIView, but the presentOpenInMenuFromBarButtonItem:animated: wants a UIBarButtonItem.

coryalder commented 12 years ago

You're absolutely right. Since I'm only using it with non-square images, I missed that scenario. Thanks for the detailed bug report!

I believe setting presentInView when you create the DMActivityInstagram will fix this, in the sort term, but I'd have to check.

Ideally there should be an way to test out this path through the code in the example app. I.e. a square image we can try sharing, to make sure it bypasses the resize view correctly.

presentInView is a UIView because I changed how this worked at the last minute. I used to call - (BOOL)presentOpenInMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated but I was having a very hard time getting that to work right on iPad, so I went with the UIBarButtonItem method instead.

Feel free to make a change and submit a pull request. Otherwise, I'll get to it when I have some free time. :)

coryalder commented 12 years ago

Alright! I've got a reasonable solution. I wasn't able to solve it by just presenting the UIDocumentInteractionController from the toolbar, as that logs and error and doesn't present the view because of the currently presented UIActivityViewController.

I toyed with a few things, but ended up going with adding a flag to DMResizerViewController that says "don't resize". If this is tripped (by DMActivityInstagram noticing that the image is square) it will immediately prompt the user to share the image, when the resizer view appears.

The resizer view still presents. We could take steps to generalize the view a bit. Like a preview window. DMPreviewViewController... or something.

Thoughts on this solution?