Uiactivityviewcontroller Completion Handler Returns Success When Tweet Has Failed

UIActivityViewController completion handler still calls action if user presses cancel

That's what the completed argument is for:

[controller setCompletionHandler:^(NSString *activityType, BOOL completed) {
if (!completed) return;

CWStatusBarNotification *notification = [CWStatusBarNotification new];
[notification displayNotificationWithMessage:@"✓ Successfully Shared Centre!"
forDuration:3.0f];

notification.notificationLabelBackgroundColor = [UIColor colorWithRed:38.0f/255.0f green:81.0f/255.0f blue:123.0f/255.0f alpha:1.0f];
notification.notificationLabelTextColor = [UIColor whiteColor];
}];

IOS swift how to know when activityViewController has been successfully used

You can add a completion handler to your UIActivityViewController. In the completion handler, check whether the user submitted using the completed value. You'll probably want to do something like this:

func sharedShareAction(controller: UIViewController, sender: UIButton) {

controller.present(activityViewController,animated: true, completion: nil)

activityViewController.completionWithItemsHandler = { activity, completed, items, error in
if !completed {
// handle task not completed
return
}
IncreaseShareByOne()
}
}

Check the API docs for more info.

UIActivityViewController completion handler is !completed when using AirDrop

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.

Is there any way to check message sent successfully from UIActivityViewController swift?

Unfortunately what you are asking is not possible.

The activity indicator will only tell you the following:

  • What option the user selected
  • Did the user complete the sharing operation (eg. Did he actually send a message)

You will not be able to know if the message was edited before being sent. The most you can do is check if the user at least selected the Message option and not, for example, the Copy option.



Related Topics



Leave a reply



Submit