开发者

How To Check If A User's iOS Device Supports Bluetooth Peer-To-Peer Connections

开发者 https://www.devze.com 2023-04-07 11:35 出处:网络
What is the best way of programatically checking if the current device supports Bluetooth peer-to-peer GameKit connectivity? I am aware of how to check for Game Center support, but want to support dev

What is the best way of programatically checking if the current device supports Bluetooth peer-to-peer GameKit connectivity? I am aware of how to check for Game Center support, but want to support devices on iOS 3 that have Bluetooth (I know all devices with bluetooth can be upgraded to iOS 4).

Edit: The app functions perfectly fine without Bluetooth, so I don't want peer-peer to be in UIRequiredDeviceCapabilities.

Many thanks in advance,

jrtc2开发者_开发百科7


Since we know which device supports what, if you can detect device you can make it work. I found this method and it works for me. You can find device capabilities here.

//Return TRUE if Device Support X.

-(BOOL)platformSupported_X
{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"])    return FALSE;
if ([platform isEqualToString:@"iPhone1,2"])    return FALSE;
if ([platform isEqualToString:@"iPhone2,1"])    return TRUE;
if ([platform isEqualToString:@"iPhone3,1"])    return TRUE;
if ([platform isEqualToString:@"iPod1,1"])      return FALSE;
if ([platform isEqualToString:@"iPod2,1"])      return TRUE;
if ([platform isEqualToString:@"iPod3,1"])      return TRUE;
if ([platform isEqualToString:@"iPod4,1"])      return TRUE;
if ([platform isEqualToString:@"iPad1,1"])      return TRUE;
if ([platform isEqualToString:@"i386"])         return TRUE;
return TRUE;
}

// Check Device Model

-(NSString *)platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}


There doesn't seem to be an elegant way to detect bluetooth peer-to-peer support based on the device type. You might want to consider basing the detection on the OS version instead (iOS 3.1 is the minimum for peer-to-peer):

NSString *reqSysVer = @"3.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osSupportsBluetoothPeerToPeer = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);

In case the OS is 3.1 or later, but the device does not support bluetooth peer-to-peer, the system will inform the user about the lack of support. This seems to be what Apple prefers: http://support.apple.com/kb/HT3621

0

精彩评论

暂无评论...
验证码 换一张
取 消