How do I check if UIActivityTypeAirDrop exists
Asked Answered
S

1

6

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)

Sympathy answered 20/9, 2013 at 11:32 Comment(0)
S
9

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];
}
Sliver answered 20/9, 2013 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.