ioscocoa-touchairdrop

Is it Correct / Possible to Explicitly Dismiss a UIActivityViewController (after AirDrop)?


In the screen shot below, some data has been successfully sent via AirDrop. The UIActivityViewController updates to show "Sent" under the recipient and Cancel is changed to Done.

enter image description here

From Apple's docs on UIActivityViewController:

Your app is responsible for configuring, presenting, and dismissing this view controller.

If the UIActivityViewController should be dismissed in the AirDrop case, should the completion handler be used for this purpose?

@property(nonatomic, copy) UIActivityViewControllerCompletionWithItemsHandler completionWithItemsHandler

Related questions:


Solution

  • After further consideration of the documentation, and the flow of events when using either a built-in activity (e.g. UIActivityTypeMail) or a 3rd-party UIActivity, I think the following...

    1) AirDrop is a special case, in that the user's interaction is performed within the UIActivityViewController itself. The UI in the UIActivityViewController updates accordingly, and the application should leave dismissing the UIActivityViewController to the user (and the Cancel / Done buttons).

    2) The completion handler is intended to be used after the UIActivityViewController has been dismissed...

    ...and not for dismissing the UIActivityViewController.

    To experiment, I added the following code:

    [controller setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
        NSLog(@"completed: %@, \n%d, \n%@, \n%@,", activityType, completed, returnedItems, activityError);
    
    }];
    

    In both cases, I get the log statement after the UIActivityViewController is gone.

    The documentation with regard to Accessing the Completion Handler is actually quite clear:

    The completion handler to execute after the activity view controller is dismissed.

    @property(nonatomic, copy) UIActivityViewControllerCompletionWithItemsHandler completionWithItemsHandler
    

    Discussion When the user-selected service finishes operating on the data, or when the user dismisses the view controller, the view controller executes this completion handler to let your app know the final result of the operation.

    I suppose it might have been more clear if this part:

    When the user-selected service finishes operating on the data...

    indicated that the user-selected service finishing would result in the dismissal of the view controller.

    3) The following, from Apple's documentation on UIActivityViewController is a little misleading:

    Your app is responsible for configuring, presenting, and dismissing this view controller.