Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect which App was launched using UIActivityViewController

When an external app is launched using UIActivityViewController, can we detect which app was used in the completionHandler?

In Apple's documentation, there is mention of a property UIActivity.ActivityType, but it seems this is used only to detect "built-in activities". How can I detect if, eg. WhatsApp Messenger was launched?

like image 452
NSAdi Avatar asked Nov 30 '18 03:11

NSAdi


1 Answers

When setting up your UIActivityViewController, use the completionWithItemsHandler to setup a completion closure that is called when the user makes a selection.

This completion block takes four parameters: the (optional) selected activity, a completion indicator, an optional array of returned items, and an error.

The selected activity is of type UIActivity.ActivityType. Its rawValue is a String representing the activity. If the activity type isn't one of the provided constants, compare its rawValue against a string you determine by running some tests to see its value for a given activity such as WhatsApp.

like image 200
rmaddy Avatar answered Sep 22 '22 05:09

rmaddy