Reputation: 6317
According to the docs [UIActivityItemProvider item]
is run on a secondary thread. This is great for not locking up the UI, but I am finding that it does not always complete by the time the item
is shown, for instance in a Mail compose screen.
I am generating a UIImage and saving this to disk, to return an NSURL. On longer running image generation tasks, it is incomplete by the time it is presented to the user. I have tried forcing it onto the main thread, but it still happens.
How can I ensure that the item
is complete?
Upvotes: 0
Views: 847
Reputation: 64
This can be done by using a boolean to hold the return of the item until the building of the file is complete. If you want to show progress or have an activity indicator show on your main view, you can do this by calling it from the main thread. Here is a code snippet of this in action:
Set the Activity View Controller in your provider with this function in order to load a progress view.
self.parentViewController = parentVc;
Here is the item function with blocking and feedback view load.
self.wait = true;
[self prepareFile:^(){
[self performSelectorOnMainThread:@selector(dismissProgressView)
withObject:nil waitUntilDone:NO];
}];
[self performSelectorOnMainThread:@selector(loadProgressView)
withObject:nil waitUntilDone:NO];
while (self.wait) {
[self performSelectorOnMainThread:@selector(updateProgressView)
withObject:nil waitUntilDone:NO];
}
return self.completedUrl;
You can then create the three functions that are called on main thread to show a progress view, update the progress view while waiting for completion of the file. In the implementation of the dismissProgressView function, make sure to set the wait boolean to false when dismissViewController is complete.
Upvotes: 1