Displaying a progress indicator during UIActivityItemProvider activity
Asked Answered
Y

1

6

I've got a UIActivityViewController which allows the user to share an image they've created to one of several activity types (facebook, twitter, save to camera roll, print, etc.).

Since I want the image to be saved/sent at different quality levels depending on the activity (high-resolution to print, low-res for twitter), I'm using a custom UIActivityItemProvider to (duh) provide the image.

Rendering the hi-res version takes some time, so I want to display an activity indicator while it's doing its thing. The apple docs make reference to doing just that, actually.

But I can't seem to figure out the "right" places to put the hooks for displaying my progress indicator... where should they go?

UPDATE: Tried the following in the - (id) activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType method:

[self performSelectorOnMainThread:@selector(startSpinnerWithMessage:) withObject:message waitUntilDone:YES];

self.shareImage = [self.delegate imageForActivityOfType:activityType]; // code that actually generates the image; takes a while.

[self performSelectorOnMainThread:@selector(endSpinner) withObject:nil waitUntilDone:YES];

...does not do the job. When I tap the activity button, the UI freezes while the image is generated, and then when it finishes, I see the spinner for a split second and then it disappears.

I think the positioning of the endSpinner call makes sense... however, it seems that the startSpinner call needs to go somewhere else. No idea what to do here.

Yaw answered 13/8, 2014 at 4:25 Comment(0)
Y
4

OK, turns out I was just going about this wrong...

I was putting my grab-the-image-from-the-delegate code in the - (id) activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType method from the UIActivityItemSource protocol. Turns out that method is fired on the main thread.

Instead, I put the same code in the UIActivityItemProvider's - (id) item method, and it works like a charm.

Yaw answered 13/8, 2014 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.