IOS quickly how to find out when ActivityViewController was successfully used

I have a tableView in which I use UIActivityViewController, so users can share content with other third-party networks Facebook, Twitter, text messages, etc. I have a function called IncreaseShareByOne(), and it is designed to count the number of times something has been split. My problem is that right now the function is triggered every time a button is pressed UIActivityViewController. Is there something that I can find out if the user really shared something so that I can use this function correctly? sometimes you open UIActivityViewControllerand decide not to share anything, so I want to catch and not use this function. I am new to fast and am using version 3.

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

    controller.present(activityViewController,animated: true,completion: nil)
    IncreaseShareByOne()
}
+4
source share
1 answer

You can add a completion handler on UIActivityViewController. In the completion handler, verify that the user is represented using the value completed. You 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()
        }
}

Learn more about the docs API for more information.

+4
source

Source: https://habr.com/ru/post/1681536/


All Articles