Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if UIActivityTypeAirDrop exists

I'm using the UIActivityViewController to show a share sheet within some iOS Apps. iOS 7 introduces a new type of UIActivity: UIActivityTypeAirDrop.

This is declared as an extern string in the UIActivity.h file... Essentially I'm trying to exclude the airdrop type from my share sheet which is all working fine, but this codeset needs to be backwards compatible with previous versions of iOS.

I know to check for a method I can use respondsToSelector: but is there any similar method I can use to check if the string is declared, or should I resort to switching on the system version? (Which is never a good way to go normally)

like image 911
Sammio2 Avatar asked Sep 20 '13 11:09

Sammio2


1 Answers

UIActivityTypeAirDrop is an NSString constant which is essentially gonna be a pointer so you can check if that pointer is NULL. If it's not, this activity type exists and you can exclude it. Else do nothing about it.

if (&UIActivityTypeAirDrop != NULL) {
    activityViewController.excludedActivityTypes = @[UIActivityTypeAirDrop];
}
like image 91
Filip Radelic Avatar answered Oct 04 '22 10:10

Filip Radelic