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)

有帮助吗?

解决方案

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];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top