5

I am using a UIActivityViewController to share a video file. The video file is generated before it's being shared using an UIActivityItemProvider.

Because the file generation and sharing can take a while for longer videos, it's important that the user can cancel the sharing operation.

This all worked without a problem in iOS7.0. The user could tap the cancel button on the UIActivityViewController at any time, and the sharing operation was canceled.

When testing the same functionality on iOS7.1.1, taps on the cancel button while a sharing operation is executed no longer work. It is as if the main thread is blocked, but all of the sharing code is executing on background threads.

Is there something I'm missing here, or is there a known issue/change in iOS7.1? (I couldn't find anything in the release notes)

UPDATE

Thanks for all the comments.

Further debugging appears to suggest that there might be a threading issue.My UIActivityItemProvider's item method is using a semaphore to make a block-based asynchronous export method defacto synchronous. Hereby also blocking the thread it is executing on. I thought this shouldn't be a problem as the documentation for the -(void)item method says:

This method is called on a secondary thread of your app.

Under iOS7.0 the UIActivityItemProvider's cancel method was called from another thread than the one using the semaphore (as expected from the documentation), but under iOS7.1, could it be called from the same (blocked) thread, causing it to never execute? I can't test for this, as the cancel method never gets executed and I'm not responsible for calling it.

Is there an alternative way to force my export method to execute synchronously without blocking? Basically my issue is that UIActivityItemProvider' item method has a long running export method, but `UIActivityItemProvider still needs to be able to receive cancel calls while it is exporting.

Tulon
  • 4,011
  • 6
  • 36
  • 56
adriaan
  • 1,574
  • 14
  • 33
  • Are you calling `cancel` on the `UIActivityItemProvider` but it doesn't cancel? Is that the problem? – progrmr May 18 '14 at 20:00
  • No that's not the problem. I present a UIActivityViewController. Its only acitivityItem is a UIActivityItemProvider. When a user selects a service to share a video to, the UIActivityItemProvider first exports a video file (using an AVAssetExportSession), then returns the local URL of the file, so the UIActivityViewController can perform the sharing / storing of that file. Even though the UIActivityItemProvider exports the video file on a background thread, the cancel button of the UIActivityViewController is unresponsive during the export on iOS7.1. On 7.0 tapping it cancels the file export. – adriaan May 18 '14 at 20:48
  • I can not get the whole picture from your description. How about add some codes and let us know more details? – Ricky May 19 '14 at 06:54
  • What do you see when you look at this using Instruments? What is the main thread doing when this happens? – quellish May 20 '14 at 01:01
  • @quellish the main thread isn't doing very much. I've got a feedback HUD updating on the main thread but that's about it. It isn't blocked. – adriaan May 20 '14 at 22:14
  • Have you tried a non-concurrent NSOperation? – quellish May 20 '14 at 22:25
  • Suggest post at least 2 or 3 lines of code, so we get the idea ! – Fattie May 24 '14 at 18:26

0 Answers0