How To Determine Whether A Device Support Airdrop?

Yuchen Z.
3 min readFeb 3, 2017

--

Airdrop is extremely handy for sharing data between iOS device wirelessly. It is available in both the UIActivityController class and the UIDocumentInteractionController class. With UIActivityController, we could share custom data in out app such as UIImage, NSString and so on. With UIDocumentInteractionController, we could share a file in the document.

The following is a list of UIActivities that are supported by UIActivityController by default.

If you have a number of possible activities, then it doesn’t matter that much if Airdrop is available or not. However, if you are using UIActivityController only for sharing custom data via airdrop, then it is very weird to see an error message No share actions available. after you hit the share button. Therefore, it is useful to known before hand whether a device supports Airdrop or not.

However, apply do not have a API for that. The only documentation we can get is the following:

To share content with AirDrop, both people need one of these devices using iOS 7 or later, or a Mac with OS X Yosemite:

  • iPhone 5 or later
  • iPad (4th generation)
  • iPad mini
  • iPod touch (5th generation)
NSString* hardwareString()
{
size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
free(hw_machine);
return hardware;
}
bool isNotOlderThan( NSString* str1, NSString* str2 ){
return [str1 compare:str2 options:NSNumericSearch] != NSOrderedAscending;
}
+ (BOOL)isSupportAirdrop
{
// From Apple Document http://support.apple.com/en-ca/ht5887
// To share content with AirDrop, both people need one of these devices using iOS 7 or later, or a Mac with OS X Yosemite:
// iPhone 5 or later
// iPad (4th generation or later)
// iPad mini
// iPod touch (5th generation)
// Borrow from Gist and StackOverFlow
// http://stackoverflow.com/questions/14411075/
// https://gist.github.com/Jaybles/1323251
// https://github.com/InderKumarRathore/UIDeviceUtil/blob/master/UIDeviceUtil.m
// You will need to test against these device to make sure it is working
// +------------------------+-------------------+
// | Models Need To Test | Support Airdrop? |
// +------------------------+-------------------+
// | iPod Touch (4 Gen) | NO
// | iPod Touch (5 Gen) | YES
// | iPhone 4S | NO
// | iPhone 5 | YES
// | iPad 2 (WiFi Rev. A) | NO
// | iPad mini (WiFi) | YES
// | iPad 3 (Global) | NO
// | iPad 4 (WiFi) | YES
//
BOOL flag = false;
NSString *hardware = hardwareString();
NSString *prefix = [hardware substringToIndex:4];
if ([prefix isEqualToString:@"iPho"]) {
// iPhone 5 and above will support Airdrop
NSString* iPhone5Hardware = @"iPhone5,1";
flag = isNotOlderThan(hardware, iPhone5Hardware);
} else if ([prefix isEqualToString:@"iPod"]) {
// iPod 4 and above will support Airdrop
NSString* iPod5Hardware = @"iPod5,1";
flag = isNotOlderThan(hardware, iPod5Hardware);
} else if ([prefix isEqualToString:@"iPad"]) {
// iPad minis, iPad 4 and above support airdrop
NSString* iPadMiniHardware = @"iPad2,5";
NSString* iPad3Hardware = @"iPad3,1";
NSString* iPad4Hardware = @"iPad3,4";
flag = (isNotOlderThan(hardware, iPadMiniHardware) && !isNotOlderThan(hardware, iPad3Hardware)) || isNotOlderThan(hardware, iPad4Hardware);
}
NSLogExport(@"Airdrop is %@supported by current device (hardware version %@)", flag ? @"" : @"not ", hardware);
return flag;
}

--

--