UIActivityViewController completion handler is !completed when using AirDrop
Asked Answered
S

1

4

I am using UIActivityViewController to share some text and url which works great when sending some text and a url.

I currently need to use the completion handler to perform additional actions depending whether the user cancelled the UIActivityViewController or actually sent something.

The completion handler (activityViewController.completionHandler for iOS 7 is deprecated in iOS 8 which is now activityViewController setCompletionWithItemsHandler) returns a BOOL completed value which correctly returns true when sending with email sms Facebook Twitter however when sending via Airdrop the user must press Cancel to dismiss the UIActivityViewController once sent and thus I always receive a false from the completion handler.

Does anyone know if there's a way of knowing that the user has sent using Airdrop when the UIActivityViewController is dismissed?

Thanks

Skeen answered 17/10, 2014 at 12:30 Comment(0)
M
13

I've found something of interest for you but unfortunately I couldn't test it as AirDrop didn't want to function between my iDevices. Sorry about that.

Anyway, you could try setCompletionWithItemsHandler checking for activityType:

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

}];

If activityType is of type com.apple.airdrop.etc (just a guess) then the user has tapped on the icon. Hope it can help.

Multi answered 28/10, 2014 at 23:55 Comment(1)
You are correct thanks. When the activityType is airdrop, it still returns completed=False however it's enough to assume it was successful. Thank you.Skeen

© 2022 - 2024 — McMap. All rights reserved.