Rohit Khatri Rohit Khatri - 1 year ago 75
iOS Question

Is it possible to know what medium is used for sharing in iOS?

I am trying to figure out if there's a way to capture the selected medium for sharing. I have an iOS app and there's a share button which shares a predefined template. When a user clicks on the share button, he is presented with the apps available that can used to share that, and if user selects Facebook or WhatsApp or Skype, they are redirected to the native apps of the medium they selected. Now I want to know what they selected.

Answer Source

You can use UIActivityViewController's completionWithItemsHandler to check which activitytype user has selected and whether they completed the activity or cancelled it:

let activityViewController = UIActivityViewController(activityItems:[ "Hello"], applicationActivities: nil)

activityViewController.completionWithItemsHandler = { (activityType, completed, returnedItems, error) in

  //check completed
  if completed{
    //check activity type using activity type
    if activityType!==UIActivityTypePostToFacebook{
   and so on 
presentViewController(activityViewController, animated: true, completion: {})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download